How to convert the following characters in some fields in a csv file?


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-26-2014
How to convert the following characters in some fields in a csv file?

I have a csv file which is produced out of a SED command
Code:
sed 's/|/","/g; s/^/"/; s/$/"/' A4.txt > A5.csv

and I need either an addition to the SED command or a separate command to convert the following characters which occur within the fields in multiple lines
1)
Code:
"="

to
Code:
="

and
2)
Code:
""~

to
Code:
"

# 2  
Old 11-26-2014
What stops you from adding the respective substitute commands
Code:
sed 's/"="/="/g;s/""~/"/g' file

to your above sed script?
And, a sample input file would be nice...
# 3  
Old 11-26-2014
can I combine everything as ??
Code:
sed 's/|/","/g; s/^/"/; s/$/"/; 's/"="/="/g; s/""~/"/g' A4.txt > A5.csv

# 5  
Old 11-27-2014
Yeah you combine but only ONE pair of SINGLE-QUOTE marks (')....


sed 's/|/","/g; s/^/"/; s/$/"/; s/"="/="/g; s/""~/"/g' A4.txt > A5.csv

Also, to prevent double quotes at the beginning and end of lines, you can add:

sed 's/|/","/g; s/^"*/"/; s/"*$/"/; s/"="/="/g; s/""~/"/g' A4.txt > A5.csv

So if a line already begins (or ends) with double- (or tripple-) quotes, it replaces them with one double-quote character.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Convert flat file to csv sandip_2014 UNIX for Dummies Questions & Answers 10 09-11-2014 11:09 AM
Inserting new fields to a csv file midhun19 Shell Programming and Scripting 3 08-28-2013 05:26 AM
Trying extract from text file and convert csv pbshillong Shell Programming and Scripting 5 03-05-2013 12:54 PM
Newline characters in fields of a file lakshmi001 Shell Programming and Scripting 6 11-05-2012 07:53 AM
Comparing two csv file fields using awk script rajak.net Shell Programming and Scripting 2 03-06-2012 09:45 AM
Convert file in csv or table alen192 Shell Programming and Scripting 5 08-24-2011 11:35 AM
How to convert a xls file to csv? cnraja Shell Programming and Scripting 4 03-18-2011 05:25 AM
pulling different fields from a csv file akdevula Shell Programming and Scripting 2 01-11-2011 06:51 AM
Convert the below file to csv format srikanth2567 Shell Programming and Scripting 6 02-10-2010 11:47 PM
convert text file to csv sais Programming 3 09-25-2009 03:31 PM
convert csv to html file sumithra UNIX for Dummies Questions & Answers 4 09-12-2009 04:45 AM
how to convert fields from a text file to excel columns npatwardhan Shell Programming and Scripting 4 12-23-2008 09:19 AM
Convert a csv file to an xls format Pablo_beezo Shell Programming and Scripting 11 09-29-2008 09:29 AM
How to work with fields of a csv file? praveen_b744 UNIX for Dummies Questions & Answers 12 09-16-2008 06:52 AM
convert fixed length file to CSV tbtbs Shell Programming and Scripting 12 08-12-2008 09:54 AM