Thursday, December 27, 2007
A 4 line paragraph - BASH beginner
Suppose we want a 4 line paragraph of the following file, i.e. every 4 lines we want as a paragraph.
$ cat para.txt
one 1
two 2
three 3
four 4
five 5
six 6
seven 7
eight 8
nine 9
....
$ awk '!( NR % 4 ) {$0 = $0"\n"} 1' para.txt
one 1
two 2
three 3
four 4
five 5
six 6
seven 7
eight 8
nine 9
....
And a traditional BASH program in the prompt itself:
$ c=0; cat para | while read line
> do
> S=`expr $c % 4`
> [ "$S" -eq 0 ] && echo "" && echo $line || echo $line
> ((c += 1))
> done | sed 1d
one 1
two 2
three 3
four 4
five 5
six 6
seven 7
eight 8
nine 9
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
No comments:
Post a Comment