Without using SED, is there shell script to copy the content from an input file to a output file, adding a blank line between every two lines of the input file (double spacing)? I
Asked
Active
Viewed 854 times
2 Answers
0
IFS=""
while read -r LINE
do
echo "$LINE"
echo
done
If it bothers you that it adds a blank line after the last line, one can do:
IFS=""
FIRST=y
while read -r LINE
do
if [ "$FIRST" != "y" ]
then
echo
fi
FIRST=n
echo "$LINE"
done
DepressedDaniel
- 4,169
- 12
- 15
0
This appears to achieve what you're after.
If NR (line number) is divisible by 2, tag an extra newline at the end. And then print the line.
$ awk 'NR%2==0{$0=$0"\n"}1' foo.txt
line1
line2
line3
line4
line5
$
If it's merely a blank line between every line, use this
$ awk '{print $0,"\n"}' foo.txt
line1
line2
line3
line4
line5
$
steve
- 21,582
- 5
- 48
- 75