Using AWK to Prepend or Append Data to Each Line

AWK is a tool that is included in Unix and most Unix variants such as Linux and Mac OS X. Using AWK, you can prepend or append data to the beginning or end of every line in a text file. Here's an example.

cat input.csv | awk '{ print "12345," $0; }'

This command will take every line from input.csv, pipe it through awk and echo it to stdout. awk in turn, will print “12345,” at the beginning of each of those lines. The $0 value means the rest of the line we passed to awk from input.csv.

If you wanted to output that data to a new file, just use the typical greater than sign to redirect to a new file (output.csv in the following example).

cat input.csv | awk '{ print "12345," $0; }' > output.csv