perl csv append column issue -


how should append column @ end of csv file using perl? can't use text::csv i'm using version 5.8.8 , package not installed here. can't upgrade newer perl version. i'm first combining several smaller csv files 1 , need add column final file. have declared handle of final file sub.

here's code snippet:

my $file = "/tmp/sub_test_".$row.".csv";         # $row in loop..so comes 1,2 etc.         open $fh, "<", $file;         <$fh> unless $file eq "/tmp/sub_test_1.csv";         print sub while <$fh>; 

i need add column header "count" , value should $row.

is row count want add?

this appends ,count first line , ,$. (which line number) rest.

then try

$ perl -e 'while (<>){chomp;if ($. ==1){print "$_,count\n"} else {print "$_,".($.-1)."\n"}}' your.csv   tmp.csv one,two,three 4,5,6 2,3,4 6,7,1  $ perl -e 'while (<>){chomp;if ($. ==1){print "$_,count\n"} else {print "$_,".($.-1)."\n"}}' tmp.csv  one,two,three,count 4,5,6,1 2,3,4,2 6,7,1,3 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -