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


 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support How to convert the following characters in some fields in a csv file?
# 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

# 4  
Old 11-27-2014
Yes U can combine.....
# 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 Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Convert flat file to csv

Hi I have a file like this: a=1 b=2 c=3 a=4 b=2 d=3 a=3 c=4 How can I change this to csv format a,b,c,d 1,2,3,, 4,2,,3 3,,4,, Please use code tags next time for your code and data. Thanks (10 Replies)
Discussion started by: sandip_2014
10 Replies

2. Shell Programming and Scripting

Inserting new fields to a csv file

hi I have a csv file with few rows > cat job_stat 1,jobname1,somthing,somthing 2,jobname2,somthing,somthing 3,jobname3,somthing,somthing 4,jobname4,somthing,somthing I want to add few columns after the 2nd column and then append rest of the columns after the 3rd newly added... (3 Replies)
Discussion started by: midhun19
3 Replies

3. Shell Programming and Scripting

Newline characters in fields of a file

My source file is pipe delimeted file with 53 fields.In 33 rd column i am getting mutlple new line characters,dule to that record is breaking into multiple records. Note : here record delimter also \n sample Source file with 6 fields : 1234|abc| \nabcd \n bvd \n cde \n |678|890|900\n ... (6 Replies)
Discussion started by: lakshmi001
6 Replies

4. Shell Programming and Scripting

Convert file in csv or table

Hi there, i have a file like that in attachment (PLEVA3_280711_SAP.txt), i would extract some basic information from it and report in a new file or table like this: i try to use bash and i extract the single object in this way (see attach scriptino.sh), but i receive a strange... (5 Replies)
Discussion started by: alen192
5 Replies

5. Shell Programming and Scripting

How to convert a xls file to csv?

Hi, My requirement is to convert the xls to csv file with utf-8 conversion. Is there any way please suggest me. Thanks, Raja (4 Replies)
Discussion started by: cnraja
4 Replies

6. Shell Programming and Scripting

pulling different fields from a csv file

Hi, I have a requirment where I need to pull different columns from a .csv file. Here is the sample of the csv file. account,item,flag1,flag2,flag3,flag4,flag5,......feed,tran I will be have a config.txt file which will have the following information. item,flag5,flag10,feed,tran... (2 Replies)
Discussion started by: akdevula
2 Replies

7. Shell Programming and Scripting

Convert the below file to csv format

Hi , i want to change this question, i will post soon.. (6 Replies)
Discussion started by: srikanth2567
6 Replies

8. Programming

convert text file to csv

hi all, i have a select query that gives me the output in the following way... SYSTYPE -------------------------------------------------------------------------------- Success Failures Total RFT ---------- ---------- ---------- ---------- TYP 1 0 ... (3 Replies)
Discussion started by: sais
3 Replies

9. Shell Programming and Scripting

how to convert fields from a text file to excel columns

i have this file which has the following contents: ,-0.3000 ,-0.3000 ,-0.3000 ,-0.9000 ,-0.9000 ,-0.9000 i would like to get this: -0.3-0.9-0.3-0.9-0.3-0.9 so far i am trying: awk '{for(i=1; i<=NF; i++) {printf("%f\n",$i)}}' test1 > test2 any help... (4 Replies)
Discussion started by: npatwardhan
4 Replies

10. UNIX for Dummies Questions & Answers

How to work with fields of a csv file?

I need to insert data into a perticular field of a csv file, lets say second field. Can any one help me to do this? I found that we can do it with sed. can any one guide me to accomplish this? thanks in advance. (12 Replies)
Discussion started by: praveen_b744
12 Replies
Login or Register to Ask a Question