![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing commas within semicolon in a flat file | r_t_1601 | Shell Programming and Scripting | 10 | 06-16-2009 06:52 AM |
| removing semicolon using sed in aix--urgent | aixjadoo | UNIX for Dummies Questions & Answers | 9 | 06-16-2008 01:41 PM |
| Removing trailer from a flat file!!! | kumarsaravana_s | UNIX for Dummies Questions & Answers | 12 | 06-24-2007 03:53 AM |
| Padding zeros after removing commas in file | pranag21 | HP-UX | 1 | 11-09-2005 10:22 PM |
| removing commas from text file | hcclnoodles | UNIX for Dummies Questions & Answers | 6 | 03-26-2003 04:43 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
||||
|
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 ======================= rohan,rahul,kunal,"sw,ati" rohan,rahul,"kun,al",swati rohan,"rah,ul",kunal,swati "ro,han",rahul,kunal,swati the output should be ============= rohan,rahul,kunal,swati how can we achieve this .. thanks in advance |
|
||||
|
if you have Python, you can use its csv module
Code:
#!/usr/bin/env python
import csv
filename = "file"
reader = csv.reader(open(filename),delimiter=",")
for row in reader:
for n,item in enumerate(row):
row[n]=row[n].replace(",","")
print ','.join(row)
Code:
# more file rohan,rahul,kunal,"sw,ati" rohan,rahul,"kun,al",swati rohan,"rah,ul",kunal,swati "ro,han",rahul,kunal,swati # ./test.py rohan,rahul,kunal,swati rohan,rahul,kunal,swati rohan,rahul,kunal,swati rohan,rahul,kunal,swati |
|
||||
|
Try the below code. This works even if you have comma more than once in a line.
Code:
use strict;
use warnings;
while(<DATA>) {
s/\"(.*?)\,(.*?)\"/$1.$2/ge;
print;
}
__END__
"ro,han",rahul,kunal,"sw,ati"
rohan,"r,ahul","kun,al",swati
rohan,"rah,ul",kunal,swati
"ro,han",rahul,kunal,"s,wati"
Last edited by balaji_red83; 06-17-2009 at 06:09 AM.. |
| Sponsored Links | ||
|
|