Furl.awk: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
(Created page with "Your data is like this: <pre> 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...") |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
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> | ||
Line 19: | Line 22: | ||
</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 ) | ||
Line 47: | Line 52: | ||
</pre> | </pre> | ||
output: | |||
<pre> | |||
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 | |||
</pre> | |||
[[Category:Script]] | [[Category:Script]] |
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