Furl.awk

From Federal Burro of Information
Revision as of 20:23, 16 July 2021 by David (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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
  1. no record seprator
  2. fixed number of fields per record
  3. 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";
}