Theodoros Emmanouilidis

Notes & Thoughts

Substitute CSV Column Values Plus One With awk


Suppose you have a three column data csv file that the values of one column, the third par example, must be substituted with current value plus one. This is very easy to do using awk.

Just type:

awk -F, '{$3++; print $1","$2","$3}' input-file.csv

awk will print by default the result to the console. To save the result you should output it to a file using:

awk -F, '{$3++; print $1","$2","$3}' input-file.csv > output-file.csv

The third column of the output file contains the input file values plus one.

posted under Tip Of The Day