Friday, May 29, 2009

Example of processing multiline records with awk

Processing multiline records is tricky. It is easier to use blank lines as record separators.


#example records
ink1 4.99
red

ink2 5.99
yellow

awk ' BEGIN { RS=""; FS=" "} { r1=$1; r2=$2; r3=$3; print "***Record***" r1 " " r2 " " r3 }' inks

#What it prints out
***Record***ink1 4.99
red
***Record***ink2 5.99
yellow

No comments:

Post a Comment