bash - Linux: Append Word Count to Each Line of a File -
quite new linux @ moment,
i've seen straightforward answers appending constant/non-changing word/component end of file e.g. shell script add suffix each line
however, i'd know how append word count each line of .csv file end of each line, that:
word1, word2, word3 foo1, foo2 bar1, bar2, bar3, bar4 becomes:
word1, word2, word3, 3 foo1, foo2, 2 bar1, bar2, bar3, bar4, 4 i working comma separated values, if there quicker/simpler way making use of commas rather items, work well.
cheers!
simple awk solution:
awk -f ',' '{print $0", "nf}' file.csv -fargument can used specify field separator,,in case.$0contain entire linenfvariable contains number of fields in line
Comments
Post a Comment