ankIT WALiA wrote:
> Hi all,
> 
> I want to retrive data from csv file.
> let us say record
> Lastname,Firstname,"Address, Apt/Suite #123",City,State,Zipcode
> when i split it using comma,
> it seprate out into
> 
> Lastname
> Firstname
> Address
> Apt/Suite #123
> City
> State
> Zipcode
> 
> but i need to store data into
> 
> Lastname
> Firstname
> Address, Apt/Suite #123
> City
> State
> Zipcode
> 

How about a quick and gross hack here? If you are sure that ctrl-A (^A) will 
never figure in the input ever. Then replace all instances of the 
separator with this before splitting and restore after splitting.

e.g. If we take this replace character as %.

$ cat test.txt
Lastname,Firstname,"Address, Apt/Suite #123",City,State,"dasd,sdas",Zipcode

$ cat test.txt| perl -ne 's/"(.*?),(.*?)"/$1%$2/g; split /,/;     foreach(@_){ 
s/%/,/g; print "$_\n";};'
Lastname
Firstname
Address, Apt/Suite #123
City
State
dasd,sdas
Zipcode


_______________________________________________
ilugd mailinglist -- ilugd@lists.linux-delhi.org
http://frodo.hserus.net/mailman/listinfo/ilugd
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi 
http://www.mail-archive.com/ilugd@lists.linux-delhi.org/

Reply via email to