Replace semicolon within double quotes in a file with semicolon delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace semicolon within double quotes in a file with semicolon delimiter
# 1  
Old 03-10-2016
Replace semicolon within double quotes in a file with semicolon delimiter

Hello Team,

Could you please help me with the below question?
I have a file with the following properties

1) File Delimiter is ;
2) Text columns are within double quotes
3) Numeric columns will not have double quotes
4) File has total 6 columns

Please see a sample record from file

Code:
"TRP";037;5;"EDA";"Paper and Paperboard";"""for production; not including office supplies.  Pulp molded"

Here the last column has a semicolon in between. As a result my script is not reading the file correctly.
Do we have a way to replace the semicolon with space?


Regards
Sam

Moderator's Comments:
Mod Comment edit by bakunin: CODE-tags added. Please use them yourself from now on. Thank you.

Last edited by bakunin; 03-10-2016 at 11:46 AM..
# 2  
Old 03-10-2016
Please use code tags as required by forum rules!

This problem has been solved several times before. Are you sure you searched theses fora? However, try
Code:
awk -F\" '{for (i=2; i<=NF; i+=2) gsub (/;/, " ", $i)} 1' OFS=\" file
"TRP";037;5;"EDA";"Paper and Paperboard";"""for production  not including office supplies. Pulp molded"

This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-10-2016
awk split
Code:
awk '{split($0,t,";");print t[1] ";" t[2] ";" t[3] ";" t[4] ";" t[5] ";" t[6] t[7]}' file

# 4  
Old 03-11-2016
Thank you Looney.

Guess I missed to mention point. The number of columns can change each time for a file. It can 6 today and 8 tomorrow...Sorry about that
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

2. Shell Programming and Scripting

SUM semicolon-seperated values from txt-file

Hello, (I'm a shell beginner) how can I sum the bold values of the following txt-file (values.txt) with bash shell. The result of the sum should be written in a new txt file (sum.txt): ... Thanks in advance (5 Replies)
Discussion started by: milu
5 Replies

3. UNIX for Dummies Questions & Answers

Delete a semicolon and numbers after a semicolon

I have this: ((9:0.010,(11:0.089,13:0.004)) and I would like this: ((A9,(A11,A13)) How do I delete the semi colon and the number (i.e. 0.010) after the semi colon? Also, how can I add the letter before the number that is NOT removed? Thank you in advance! ---------- Post updated... (4 Replies)
Discussion started by: MDeBiasse
4 Replies

4. Shell Programming and Scripting

Replace dot with semicolon in PERL

Hi, I have a file in PERL in the following pattern filename| 06-Dec-11 03.04.14.000000 PM filename1| 06-Dec-11 05.05.14.000000 PM I need to replace .(dot) with :(semicolon) in the timestamp value of the file How can this be done. Any help will be appreciated Thanks in advance (5 Replies)
Discussion started by: irudayaraj
5 Replies

5. Shell Programming and Scripting

Replace a string after n semicolon every line

I have a file that is formatted in this way. a1;b2;c33;d4;e5;e;f;f;f;s d;ds;d;a;v;b;g;gr;r;rt;fdf s1;s2;s2;s3;s4; b1;f2;g3;h4;a3c4e;xcsd;fds; sd2;fs4;fs2;sdf3; I want to replace the value just before the 4th semicolon to empty string, regardless the value, such that it looks... (3 Replies)
Discussion started by: alienated
3 Replies

6. Shell Programming and Scripting

Extract semicolon separated delimiter

The log reads as follows. fname1;lname1;eid1;addr;pincode1; fname2;lname2;eid2;addr2;pincode2; fname3;lname3;eid3;addr3;pincode3; fname4;lname4;eid;addr4;pincode4; how do i extract only fname and save it in an array similarly for lname and so on i tried reading a file and cutting each... (5 Replies)
Discussion started by: vkca
5 Replies

7. Shell Programming and Scripting

Replace blank spaces with semicolon - text file

Hi all, Been trying to find a solution to this, I'm sure its a sed 1 liner, but I don't know sed well enough to work it out... I have a text file in the following format: 431 666 1332 2665 0.24395 432 670 ... (3 Replies)
Discussion started by: mpcengineering
3 Replies

8. Shell Programming and Scripting

Removing commas within semicolon in a flat file

i am recieving a flat file ( comma seperated ) with comma in between double quotes in any of the source fields . i need to remove the comma in double quotes and process the file thereafter fields in file ========= col1,col2,col3,col4 input can be any of the followng... (31 Replies)
Discussion started by: r_t_1601
31 Replies

9. Shell Programming and Scripting

Removing commas within semicolon in a flat file

Hi , Im relatively new to unix and have to process a comma serparated flat file . I recieve some of the fields in double quotes and i want to remove it .. INPUT ==== filed1,field2,field3,"fie,ld4" OUTPUT ===== field1,field2,field3,"field4" can anyone tell me how to achieve... (10 Replies)
Discussion started by: r_t_1601
10 Replies

10. Shell Programming and Scripting

put a semicolon at the end of each line of a file

hi, Consider there is a file containing 200 lines. please let me know which command is to be used to put a semicolon at the end of each line. if no single command is there then how it can be achieved. (1 Reply)
Discussion started by: surjyap
1 Replies
Login or Register to Ask a Question