46019
January 4, 2011, 9:35am
1
Hello...
I have a file which contain certain number of records.
I want to generate another file from this file which will contain 1st line as a blank line & after every 5 lines one blank line will be inserted. How to achieve this through shell scripting?
Thanks...
awk '{ print; } NR % 5 == 0 { print ""; }' inputfile...
46019
January 4, 2011, 10:19am
3
Lets say I have file FILE1 which contains 100 records.
FILE1
------------
aaaaaaaaaaaa
bbbbbbbbbbbb
cccccccccccc
dddddddddddd
eeeeeeeeeeee
fffffffffffffffffff
gggggggggggg
hhhhhhhhhhhh
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
jjjjjjjjjjjjjjjjjjjjjjj
kkkkkkkkkkkkk
lllllllllllllllllllllllllllll
mmmmmmmmm
nnnnnnnnnnnn
oooooooooooooo
ppppppppppppppp
I want to add a header record before the first record & after every 5th record so that file will look like this.
record set-1
aaaaaaaaaaaa
bbbbbbbbbbbb
cccccccccccc
dddddddddddd
eeeeeeeeeeee
record set-2
fffffffffffffffffff
gggggggggggg
hhhhhhhhhhhh
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
jjjjjjjjjjjjjjjjjjjjjjj
record set-3
kkkkkkkkkkkkk
lllllllllllllllllllllllllllll
mmmmmmmmm
nnnnnnnnnnnn
oooooooooooooo
record set-4
ppppppppppppppp
How to achieve this?
awk '(NR-1)%5||$0="record set-"++i RS $0' infile
awk ' BEGIN {print "record set -1"; rec=1}
{print $0
if (NF%5 == 0 ) {rec++; print "record set -" rec} } ' infile > outfile
try that
Or:
awk 'NR % 5 == 1 { print "record set-" ++rec; } { print; }' inputfile
> TIMTOWTDI