Furl.awk: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 19: | Line 19: | ||
</pre> | </pre> | ||
# no record | axiom / assumption: | ||
# no record separator | |||
# fixed number of fields per record | # fixed number of fields per record | ||
# number of field is 5 ( obviously you can change this to suit ) | # number of field is 5 ( obviously you can change this to suit ) |
Revision as of 15:36, 2 November 2022
Your data is like this:
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