[NTLUG:Discuss] scripting foo help
Stuart Johnston
saj at thecommune.net
Thu Jul 2 11:15:47 CDT 2009
Dan Wright - SPCA of Texas wrote:
> my scripting foo is week.....
>
> I have a CSV file that needs " added to the ID fields like bellow, right
> now there missing the " ( ex: 1263831 instead of: "1263831" and ID
> instead of: "ID" )
>
Here is a Perl solution. It will read from data.csv and print the
result to stdout. You can add '-i' if you want it to modify the file
inplace.
perl -n -a -F"," -e '$F[0]=qq{"$F[0]"};print join(q{,}, @F);' data.csv
If you have any newlines within your data fields, this will break.
You'd need a full csv parser to handle that.
More information about the Discuss
mailing list