Furl.awk: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Your data is like this: | |||
opposite of "unfurl" | |||
Your data is like this:. "furl" is a word, who knew? | |||
<pre> | <pre> |
Latest revision as of 15:37, 2 November 2022
opposite of "unfurl"
Your data is like this:. "furl" is a word, who knew?
record 1 field 1 record 1 field 2 record 1 field 3 record 1 field 4 record 1 field 5 record 2 field 1 record 2 field 2 record 2 field 3 record 2 field 4 record 2 field 5 record 3 field 1 record 3 field 2 record 3 field 3 record 3 field 4 record 3 field 5
axiom / assumption:
- no record separator
- fixed number of fields per record
- number of field is 5 ( obviously you can change this to suit )
try this:
awk -f furl.awk datafile.txt
ful.awk is:
{ if ( NR%5 == 1 ) printf "%s," , $0 else if ( NR%5 == 2 ) printf "%s," , $0 else if ( NR%5 == 3 ) printf "%s," , $0 else if ( NR%5 == 4 ) printf "%s," , $0 else if ( NR%5 == 0 ) print $0 else print "NOPE"; }
output:
record 1 field 1,record 1 field 2,record 1 field 3,record 1 field 4,record 1 field 5 record 2 field 1,record 2 field 2,record 2 field 3,record 2 field 4,record 2 field 5 record 3 field 1,record 3 field 2,record 3 field 3,record 3 field 4,record 3 field 5