i would to know how can i edit my csv file to add first column with name 'linenumber' and iterate through each line and insert the number of the line in this column ?
Something like that
TEST TEST2 TEST3
valu value value
To that
linenumber TEST TEST2 TEST3
1 valu value value
Thanks in advance
Stoufiler
Following awk should help you on same.
awk 'FNR==1{print "linenumber",$0;next} {print FNR-1,$0}' Input_file
In case you need to edit the Input_file itself then following may help you.
awk 'FNR==1{print "linenumber",$0;next} {print FNR-1,$0}' OFS="," Input_file > temp_file && mv temp_file Input_file
i found the answer, it's that
awk 'FNR==1{print "linenumber,"$0;next} {print FNR-1,$0}' OFS="," input.csv > output.csv
thanks for all
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.