Differences

This shows you the differences between two versions of the page.

Link to this comparison view

using_awk_to_prepend_or_append_data_to_each_line [2012/08/29 20:56] (current)
Joel Dare created
Line 1: Line 1:
 +====== 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
  
 

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