Learn to Code by Making Art
Learn programming while your create computer art by copying code from my free guide.
https://splashofcode.com

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
Learn to Code by Making Art
Learn programming while your create computer art by copying code from my free guide.
https://splashofcode.com
comments powered by Disqus
using_awk_to_prepend_or_append_data_to_each_line.txt · Last modified: 2012/08/29 20:56 by Joel Dare