Insert a new line after every N lines?
With awk
:
awk ' {print;} NR % 2 == 0 { print ""; }' inputfile
With sed
(GNU
extension):
sed '0~2 a\\' inputfile
With bash
:
#!/bin/bash
lines=0
while IFS= read -r line
do
printf '%s\n' "${line}"
((lines++ % 2)) && echo
done < "$1"
Using paste
paste -d'\n' - - /dev/null <file
sed n\;G <infile
... is all you need ...
For example:
seq 6 | sed n\;G
OUTPUT:
1
2
3
4
5
6
...(and a blank follows the 6 as well)...or...
seq 5 | sed n\;G
OUTPUT:
1
2
3
4
5
(and no blank follows the 5)
If a blank should always be omitted in a last line case:
sed 'n;$!G' <infile