Replacing csv commas with tabs
Has anyone come accross a command, preferably in vi to replace comma's seperated fields with tab delimited fields? I know about the substitution command but as people who work with csv files might know that fields of data with commas in them have quotation marks around them, I need to keep these commas in the file.
Not sure if I understand this 100%
But if I do, then this should work:
`fixcsv.py inputfile outputfile`
Things that are quoted because they contain a comma will no longer be quoted since thats no longer the delimiter (tab is). Also, you can uncomment the commented out line to have every field surrounded in quotes.
#!/usr/bin/python
#fixcsv.py
import csv
import sys
reader = csv.reader(open(sys.argv[1], "rb"))
writer = csv.writer(open(sys.argv[2], "wb"), delimiter='\t')
#uncomment next line if you want everything quoted
#writer = csv.writer(open(sys.argv[2], "wb"), delimiter='\t', quoting=csv.QUOTE_ALL)
writer.writerows(reader)
Be sure to backup your data just in case.
Last edited by sabooky (2007-06-06 05:00:14)
Similar Messages
-
Calculated formula for replacing a comma with a Semicolon in a text field
I need help replacing a comma with a Semicolon in a text field.
I have a field that has names separated by commas.
Ex: Dog, Cat, Bird, Horse, Eagle, Worm, Snake
I would like a calculated column that converts the field into: Dog; Cat; Bird; Horse; Eagle; Worm; Snake
I figured out the first three positions (Dog, Cat, Bird,) but I can't figure out the rest.
Using the formula below.
=REPLACE((REPLACE((REPLACE([Title],SEARCH(",",[Title]),"1"," ; ")),SEARCH(",",(REPLACE([Title],SEARCH(",",[Title]),"1"," ; "))),"1"," ; ")),SEARCH(",",(REPLACE((REPLACE([Title],SEARCH(",",[Title]),"1","
; ")),SEARCH(",",(REPLACE([Title],SEARCH(",",[Title]),"1"," ; "))),"1"," ; "))),"1"," ; ")
Please helpcheck the similar post
http://social.technet.microsoft.com/Forums/windowsserver/en-US/66e2ae2a-4da9-4c58-a8bb-cf46b1bf448f/calculated-column-to-replace-commas?forum=sharepointgenerallegacy -
How to upload .csv file with tab as delimiter.
HI,
I want to upload a .csv file with tab as delimiter to unix path in background.
I know there is function module 'GUI_UPLOAD', but in my case data is available in an internal table .
upload the *.CSV :
OPEN DATASET lv_filename
FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
* Write file records into file on application server
LOOP AT gt_datatab INTO gs_datatab.
TRANSFER gs_datatab TO lv_filename.
ENDLOOP.
CLOSE DATASET lv_filename.Bhanu,
Define a local variable of type CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
LV_TAB TYPE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
LOOP AT GT_DATATAB INTO GS_DATATAB.
CONCATENATE GS_DATATAB-FIELD1
GS_DATATAB-FIELD2
GS_DATATAB-FIELDN
INTO LV_STRING SEPARATED BY LV_TAB.
TRANSFER LV_STRING TO lv_filename.
ENDLOOP.
Thanks,
Vikram.M -
Replace last comma with ' and '
Hi All,
please let me know is there any simple way of replacing last comma in as string with ' and '
eg: 1. abc,xyz,wuv should be returned abc,xyz and wuv
2. abc,wuv should be returned abc and wuv
3. abc,pqr,cuq,wuv should be returned abc ,pqr,cuq and wuv
DB version : 11.2.0.3
Thanks,
DSWith only SUBSTR and INSTR:
<LQS with sample_data as ( select 'abc,xyz,wuv' str from dual union
2 select 'abc,wuv' from dual union
3 select 'abc,pqr,cuq,wuv' from dual
4 )
5 --
6 -- actual query
7 --
8 select str
9 , substr(str, 1, instr(str, ',', -1)-1)||' and '||substr(str, instr(str, ',', -1)+1)
10 from sample_data;
STR SUBSTR(STR,1,INSTR(STR,',',-1)-1)||
abc,pqr,cuq,wuv abc,pqr,cuq and wuv
abc,wuv abc and wuv
abc,xyz,wuv abc,xyz and wuv
3 rows selected. -
Replacing a comma with a paragraph mark
Hello All,
I have some poor quality address information which is in the form:
<ADDRESS>1 High Street, Kensington, London, England, SW1<!ADDRESS>
and on the letter I need to convert it into:
1 High Street
Kensington
London
England
SW1
Any clues how to do this conversion?
Help appreciated.
Regards
RichardIf the fields remain constant, then you know how many commas are present. Given that, you can instring and substring the entire string based on the commas.
You can test this out in SQL using a table.
create table bip (address varchar2(60));
insert into bip values
('1 High Street, Kensington, London, England, SW1');
In SQL*Plus:
col a for a13
col b for a12
col c for a12
col d for a12
col e for a12
--this will show each part of the address, but all on one line
select
--first part
substr(address,1, instr(address,',',1,1)-1) "A",
--second part
substr(address, instr(address,',',1,1)+2, instr(address,',',1,2)-instr(address,',',1,1)-2) "B",
--third part
substr(address, instr(address,',',1,2)+2, instr(address,',',1,3)-instr(address,',',1,2)-2) "C",
--fourth part
substr(address, instr(address,',',1,3)+2, instr(address,',',1,4)-instr(address,',',1,3)-2) "D",
--fifth part
substr(address, instr(address,',',1,4)+2) "E"
from bip;
A B C D E
1 High Street Kensington London England SW1
--this will line return after each part of the address
select
--first part
substr(address,1, instr(address,',',1,1)-1) ||chr(10)||
--second part
substr(address, instr(address,',',1,1)+2, instr(address,',',1,2)-instr(address,',',1,1)-2) ||chr(10)||
--third part
substr(address, instr(address,',',1,2)+2, instr(address,',',1,3)-instr(address,',',1,2)-2) ||chr(10)||
--fourth part
substr(address, instr(address,',',1,3)+2, instr(address,',',1,4)-instr(address,',',1,3)-2) ||chr(10)||
--fifth part
substr(address, instr(address,',',1,4)+2) "ADDRESS"
from bip;
ADDRESS
1 High Street
Kensington
London
England
SW1
What you do in Desktop (xpath query) is to write the select part for each element. -
REPLACEMENT OF COMMA WITH FULLSTOP
HI ALL,
I AM WORKING ON AN ISSUE WHERE I AM FACING A PROBLEM OF COMMA AND FULL STOP.I MEAN THE VALUES SAY NET VAL IS GETTING PRINTED LIKE <b>2.500,45</b> INSTEAD THE VALUE SHOULD BE <b>2,500.45</b> ,AND I NEED A SUGGESTION FOR THIS ISSUE.AND I HAVE EVEN CHECKED IN SETTINGS IT IS PROPER.DO WE HAVE ANY SUCH FUNCTION MODULE.
THANKS AND REGARDSHi,
U can use the statement
SET COUNTRY f.
Displays the decimal point in subsequentoutput (WRITE) according to the settings specified in the tableT005X for the country ID f.
IN ur case use the following :
SET COUNTRY 'DE'.
If u change the settings, in User profile, then it will be effective only for that user, but its not sure that i.e only user who will exceute, there might be any number of users who will exceute that. So it should not be user dependent.
Revert back if any issues,
reward if helpful.
regards,
naveen
Message was edited by:
Naveen Deva -
Powershell (Replacing White Spaces with a comma)
The object property values output tends to be tabular with varying white spaces between each column. I’m looking for a script that will allow me to:
Output the object property values to a file
Remove all white spaces encountered (regardless of the number of spaces)
Replace the spaces with one (1) comma
Replace isn’t the answer unless I literally define each instance of spaces and I can’t find any discernable documentation on using Regex…
-- formattting the output doesn't help either...
Any guidance / help would be appreciated
RoderickLet's say I ran the PowerShell command below:
Get-ClusterResource -Cluster ClusterName | Where-Object {$_.Name -like "SQL Server (*"}
The output would be something along lines of what you see below.
I typically output the result set to a csv file, strip the header, replace the spaces with a single comma, and bulk import the data into a SQL Server table for reporting.
Basically, I'd like a "dynamic way" (not replace with the literal space count between double quotes) of getting rid of the spaces between the columns and replace the spaces with a single comma.
Name State
Group ResourceType
SQL Server (SRV101O) Online SRV101o SQL Server
SQL Server (SRV301O) Online SRV301o SQL Server
SQL Server (SRV201O) Online SRV201o SQL Server
SQL Server (REMSRV101O) Offline REMSRV101o SQL Server
SQL Server (REMSRV301O) Offline REMSRV301o SQL Server
SQL Server (REMSRV201O) Offline REMSRV201o SQL Server
SQL Server (REMSRV401O) Offline REMSRV401O SQL Server
SQL Server (REMSRV501O) Offline REMSRV501O SQL Server
SQL Server (SRV401O) Online SRV401O SQL Server
SQL Server (SRV501O) Online SRV501O SQL Server -
My Firefox v6.02 browser always open *.csv (comma delimited) file in another tab rather than downloading a file? I do not have right click option to save this file. My OP is windows XP sp2.
Hi mha007,
Go to this site "http://www.nseindia.com/content/indices/ind_histvalues.htm"
Select any Index type and from dates select just one day or any number of days. Click "Get Details" button. This will open tabular data on loaded page (with link CSV file link at bottom).
When I click this link, it opens CSV file in new tab (in Firefox browser) and does not open download window (just as in case of other file formats like *.zip, *.rar or *.xls).
Right-click of link does not give "save as" or "save file" option.
Firefox is my preferred and default browser.
========
surprisingly, When I do same thing in IE6 browser, data-table page shows 2 options below table, i.e. (1) download file (2) open file. -
Unable to Load CSV file with comma inside the column(Sql Server 2008)
Hi,
I am not able load an CSV file with Comma inside a column.
Here is sample File:(First row contain the column names)
_id,qp,c
"1","[ ""0"", ""0"", ""0"" ]","helloworld"
"1","[ ""0"", ""0"", ""0"" ]","helloworld"
When i specify the Text Qualifier as "(Double quotes) it work in SQL Server 2012, where as fail in the SQL Server 2008, complaining with error:
TITLE: Microsoft Visual Studio
The preview sample contains embedded text qualifiers ("). The flat file parser does not support embedding text qualifiers in data. Parsing columns that contain data with text qualifiers will fail at run time.
BUTTONS:
OK
I need to do this in sql server 2008 R2 with Service pack 2, my build version is 10.50.1600.1.
Can someone let me know it is possible in do the same way it is handle in SQL Server 2012?
Or
It got resolved in any successive Cumulative update after 10.50.1600.1?
Regards HarshHello,
If you have CSV with double quotes inside double quotes and with SSIS 2008, I suggest:
in your data flow you use a script transformation component as Source, then define the ouput columns id signed int, Gp unicode string and C unicode string. e.g. Ouput 0 output colmuns
Id - four-byte signed
gp - unicode string
cc - unicode string
Do not use a flat file connection, but use a user variable in which you store the name of the flat file (this could be inside a for each file loop).
The user variable is supplied as a a readonly variable argument to the script component in your dataflow.
In the script component inMain.CreateNewOutputRows use a System.IO.Streamreader with the user variable name to read the file and use the outputbuffer addrow method to add each line to the output of the script component.
Between the ReadLine instraction and the addrow instruction you have to add your code to extract the 3 column values.
public override void CreateNewOutputRows()
Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
string line;
System.IO.StreamReader file = new System.IO.StreamReader( Variables.CsvFilename);
while ((line = file.ReadLine()) != null)
System.Windows.Forms.MessageBox.Show(line);
if (line.StartsWith("_id,qp,c") != true) //skip header line
Output0Buffer.AddRow();
string[] mydata = Yourlineconversionher(line);
Output0Buffer.Id = Convert.ToInt32(mydata[0]);
Output0Buffer.gp = mydata[1];
Output0Buffer.cc = mydata[2];
file.Close();
Jan D'Hondt - SQL server BI development -
Dear all,
I'm getteing mad with the following issue and need your help.
I'm working at a PDF-Form including a table. The Values in this table create a datamatrix. This works fine for now.
Here is my issue: The values in the table are numbers like 12.2 but also 12 or 9 but maximum two digits in front of the "."(dot). Seperation character should be a "." In Germany there is the ","(comma) instead of the "." at the number block.
For better usability it would be nice having a java script that replaces onBlur all "," with a ".". So I don't have to change the keyboard language to English.
Is this possible and if yes, how?
I am an absolutely noob on javascript, so please be patient and do not expect any specific knowledge.
What I tried (menue is translatet from the German version, I don't know if it is correct:
onBlur.replace(",", ".");
I put this in (right click on form) -> properties ->action ->
add action: on mouse exit
choose action: run JavaScript
click on "add"
Then I copied the terminus from the top in the opening window. Ready (at least this was my thought...)
It dit not work, now I nedd your help.
Thank you for your hints, your help and your time.
Adobe Acrobat XI (German) on Windows 7 64bit (also german).***************SOLVED**********************
The solution was much easier than expected:
when you open "properties" by right clicking on the form, go to "validation" NOT "action" (make sure you are in the form editing mode: "tools" -> "forms" -> "edit")
then chose "run user defined script" and click on "edit"
type in the following line:
event.value = event.value.replace(/\,/g, ".");
click "OK" and then "Close"
Then you are done. Now, when you leave the form field Acrobat checks if there is a comma and replaces it with a dot.
For me this was the easiest way to make it work.
***************SOLVED**********************
***************GELÖST**********************
Die Lösung war einfacher als gedacht.
Öffnet man "Eigenschaften" mit einem Rechtsklick auf das Formular, muss man "Validierung" und nicht "Aktionen" auswählen. (man muss im Formulareditierungsmodus sein: "Werkzeuge" -> "Formulare" -> "Bearbeiten")
dann unter "Benutzerdefiniertes Validierungsskript ausführen" auf "Berabeiten" klicken.
Im Editorfenster folgende Zeile eingeben:
event.value = event.value.replace(/\,/g, ".");
Über "OK" und "Schließen" zurück zu den Eigenschaften
Das war's. Nun ersetzt Acrobat im Formularfeld jedes Komma durch einen Punkt.
***************GELÖST********************** -
Replace each third comma with ||
Hi All,
My Requirement is like this:
In a column i need to replace every third comma(,) with || symbol.
eg:
1,Animesh,1234,2,Tripathi,4321,3,Oracle,2345.....(and so on)
Desired output:
1,Animesh,1234||2,Tripathi,4321||3,Oracle,2345....Please help me out.
Regards
Animesh
Edited by: Animesh Tripathi on Dec 11, 2012 2:22 AMAnimesh Tripathi wrote:
Hi LPS,
Sorry for duplicating the post.
The reason i duplicated this is because, earlier i did not get any proper answer for this and I thought of replicating this
to another community.
AnimeshHi Animesh,
you have posted again the same question to have again the same exact answer.
I have answered you previously and you seemed also satisfied in this thread: {message:id=10739356}:
Animesh Tripathi wrote:
Hi Alberto,
That was what i exactly wanted.
Thanks for the Help.
Regards
AnimeshWhy are you saying you did not get a proper answer?
Did you face any problem with previous solution?
Regards.
Al -
Replace comma with a character only if it is enclosed in single quotes
I have a string
String stmt = "insert into ABC values (Default,'ABC','1234,xyz,abc');{code}
expected the result is
insert into ABC values (Default,'ABC','1234~xyz~abc')
I want to replace only those commas with a ~ if they are part of the string enclosed in a pair of singe quotes.
i am trying something like
{code}String regex = "\'\\w+(,)+\\w*,*\\w*\'+\1";
String output = stmt.replaceAll(regex,"~");
{code}
but its not working
Please help.LearningMachine wrote:
No, that's not what I am trying to do.
This is not an insert into a sql, I have to parse a DML (SQL Script) and get table name, values out of it, but I can't split the string with commas.
Then you should find or build a parser.
Unless the DML is very well constrained or the set is very small and will remain so, by the time you finish mucking around with all the possibilities attempting it with regexes you will have a parser but not a very good one. -
Hi,
Note : I am using SAP 4.6
Task : Replace Comma with space
Problem : Not able to replace comma with space
I have task where I have to write result file to application server, when I am writing string to application server it is separating by comma, for example if you take below statement it is dividing by space that means in first column PO and then ITEM etcu2026.
MOVE 'PO ITEM is not there in table EKPO' TO W_RECORD_OUT-ERROR_MSG.
so to resolve this situation I have used below code for now, I know I can use
REPLACE ... ALL ENTRIES but this statement is not working in SAP 4.6
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
CONDENSE W_RECORD_OUT-ERROR_MSG.
appreciate if somebody can help me.
Thanks
sarathHi,
Please check the below code.
REPORT YSAT_TEST.
Data: Var1(40) type c value 'Test1,Test2,Test3,Test4'.
break-point.
REPLACE ',' WITH space INTO Var1. " It will replace only first occurrence
replace all occurrences of ',' in var1 with ' '.
CONDENSE Var1 no-gaps.
write: var1. -
Catproc.sql gives ORA-02303: cannot drop or replace a type with type or tab
I am running catproc.sql and am seeing several of the following errors. Appreciate any insight into the problem. Thanks..
CREATE OR REPLACE TYPE ODCIObject AS object
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependents
CREATE OR REPLACE TYPE ODCIObjectList AS VARRAY(32) of ODCIObject;
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependentsI am in the process of doing a test upgrade of Oracle E-business 11.0.3 with Oracle 8.0.6 to Oracle E-business 11.5.10.2 with Oracle 9.2.0.
I am following the upgrade manual:
Oracle Applications – Upgrading Oracle Applications
Release 11i (11.5.10.2)
Part No. B19297-01
I have already upgraded the database from 8.0.6 to 9.2.0 using the Oracle database migration utility at the appropriate point in the instructions.
After upgrading the database to 9.2.0 as stated in this manual, one of the of the next Oracle Application pre-upgrade tasks is to execute a script called addb920_nt.sql which in turn executes catalog.sql and catproc.sql. I am seeing these errors when catproc.sql is executed.
I have logged an Oracle Support SR and am awaiting a response, but wanted to know if anyone had seen similar issues.
Thanks,
Alma -
Office Web Apps Server 2013 - Word Web App - Problem with Tab space
Hello We have Office Web Apps Server 2013 running with SharePoint 2013. Users Editing a Word document with Office Web Apps, can't use "Tabs", any Word document with Tabs; the tabs are replaced with a single space.
Has anyone noticed this? Is this a bug?
-thanks
thomas
-TomYes, currently the Word Web App does not support
Tab Keyboard shortcut for editing document content .
For more information, you can have a look at
the article:
http://office.microsoft.com/en-us/office-online-help/keyboard-shortcuts-in-word-online-HA010378332.aspx?CTT=5&origin=HA010380212
http://social.technet.microsoft.com/Forums/en-US/3f5978d3-67a1-4c8c-981f-32493d72610b/office-web-apps-server-2013-word-web-app-problem-with-tab-space?forum=sharepointgeneral
Maybe you are looking for
-
How do I access my itunes library with apple tv
I use itunes on my Ipad 1 and on my ibm computer with windows xp. I have just acquired an Apple TV. The literature tells me I can access my ibm computer's itunes library on my Apple TV by using home sharing but it just doesn't seem to work. I have
-
Just installed OSX 10.6.8 and Can't Buy from App Store
I have installed Snow Leopard 10.6.8 and ran Software Update, and now I want to upgrade to Lion. I can open App Store, log in, access my account, but when I try to purchase Lion I get a message "We could not complete your request. There was an error
-
hello, where should I look for documentation on org and javax packages? I mean, if I see a function from the java package, I can google it and find out which are it's constructors, methods, what it implements or extends etc. But if I see for instance
-
How do I add keywords to my images using DW?
How do I add keywords to my images using DW?
-
i using LR5.its gone part of base.like contrast,dark,light,shadow..things.how to get back it?