Forum Discussion
hooleylist
Apr 18, 2012Cirrostratus
And an even simpler awk example from James Quinby:
awk 'BEGIN{RS=" \n";FS="\n"};{print $3,$4}' input.txt | awk '{print "\042"$2"\042 := \042"$4"\042,"}'
First awk breaks the records by blank-lines (RS) and the fields (FS) by newlines – this prints the last 2 lines of each record side-by-side.
Second awk splits by spaces and prints the correct fields, delimiter and double-quotes.
N.B.: The sample input was a space on a blank line between records – you’ll want to adjust the RS in that first awk accordingly if the actual record separator is a true bare linefeed. This could probably be combined into a single awk script.
Aaron