Re: [ilugd] How to remove comma(') from CSV file

2007-07-01 Thread ankIT WALiA
In case of any number of commas

On 6/29/07, Raj Mathur [EMAIL PROTECTED] wrote:

 On Friday 29 June 2007 15:57, ankIT WALiA wrote:
  Hi all,
  I want to retrive data from csv file.let us say
  recordLastname,Firstname,Address, Apt/Suite
  #123,City,State,Zipcodewhen i split it using comma,it seprate out
  into LastnameFirstnameAddressApt/Suite #123CityStateZipcode
  but i need to store data into
  LastnameFirstnameAddress, Apt/Suite #123CityStateZipcode
  I am usingvar oFile = Clib.fopen(vFilepath,r);var string =
  (Clib.fgets(oFile));if(string)
  {   var arr = string.split(,);
} Please suggest something..

 Something like this?

 echo 'recordLastname,Firstname,Address, Apt/Suite
 #123,City,State,Zipcodewhen'| \
 perl -MText::CSV -e \
 '$c=Text::CSV_XS-new();$s=$c-parse(STDIN);@c=$c-fields;map{print
 $_\n} @c;'

 recordLastname
 Firstname
 Address, Apt/Suite #123
 City
 State
 Zipcodewhen

 Regards,

 -- Raju
 --
 Raj Mathur [EMAIL PROTECTED] http://kandalaya.org/
   GPG: 78D4 FC67 367F 40E2 0DD5 0FEF C968 D0EF CC68 D17F
   It is the mind that moves

 ___
 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/




-- 
LIfe is like a Rose is upto u spreading its fragnance or thorns.
अन्कित वालिया
___
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/


[ilugd] How to remove comma(') from CSV file

2007-06-29 Thread ankIT WALiA
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

I am using
var oFile = Clib.fopen(vFilepath,r);
var string = (Clib.fgets(oFile));
if(string)
{
   var arr = string.split(,);
}

Please suggest something..

Thanks
-- 
LIfe is like a Rose is upto u spreading its fragnance or thorns.
अन्कित वालिया
___
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/


Re: [ilugd] How to remove comma(') from CSV file

2007-06-29 Thread Sandip Bhattacharya
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/


Re: [ilugd] How to remove comma(') from CSV file

2007-06-29 Thread Saleem Ansari
#!/usr/bin/perl
# filename: csv.pl
use strict;
use warnings;

foreach(){
  my ($names, $address, $rest)  = split '';
  my ($lastname, $firstname, $waste, $city, $state, $zip)
= (split (/,/ , $names), split(/,/ , $rest));
  print join( \n,
($lastname, $firstname, $address, $city, $state, $zip)),
\n;
}



$ ./csv.pl  data.txt
Lastname
Firstname
Address, Apt/Suite #123
City
State
Zipcode




On 6/29/07, ankIT WALiA [EMAIL PROTECTED] 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

 I am using
 var oFile = Clib.fopen(vFilepath,r);
 var string = (Clib.fgets(oFile));
 if(string)
 {
var arr = string.split(,);
 }

 Please suggest something..

 Thanks
 --
 LIfe is like a Rose is upto u spreading its fragnance or thorns.
 अन्कित वालिया
 ___
 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/




-- 
o1p2e3n4g5l6
http://saleem.a.ansari.googlepages.com/
http://www.jmilug.org/
http://www.csijmi.com/
Linux User #414799 (http://counter.li.org/)
___
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/


Re: [ilugd] How to remove comma(') from CSV file

2007-06-29 Thread Raj Mathur
On Friday 29 June 2007 15:57, ankIT WALiA wrote:
 Hi all,
 I want to retrive data from csv file.let us say
 recordLastname,Firstname,Address, Apt/Suite
 #123,City,State,Zipcodewhen i split it using comma,it seprate out
 into LastnameFirstnameAddressApt/Suite #123CityStateZipcode
 but i need to store data into
 LastnameFirstnameAddress, Apt/Suite #123CityStateZipcode
 I am usingvar oFile = Clib.fopen(vFilepath,r);var string =
 (Clib.fgets(oFile));if(string)   
 {   var arr = string.split(,); 
   } Please suggest something..

Something like this?

echo 'recordLastname,Firstname,Address, Apt/Suite 
#123,City,State,Zipcodewhen'| \
perl -MText::CSV -e \
'$c=Text::CSV_XS-new();$s=$c-parse(STDIN);@c=$c-fields;map{print $_\n} 
@c;'

recordLastname
Firstname
Address, Apt/Suite #123
City
State
Zipcodewhen

Regards,

-- Raju
-- 
Raj Mathur           [EMAIL PROTECTED]   http://kandalaya.org/
       GPG: 78D4 FC67 367F 40E2 0DD5  0FEF C968 D0EF CC68 D17F
                      It is the mind that moves

___
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/