11

I want to insert 5 blank lines after every line in my input file.

foo.txt:

line 1
line 2
line 3

out.txt:

line 1





line 2





line 3    





...

Solaris 5.10, nawk or sed.

cuonglm
  • 150,973
  • 38
  • 327
  • 406
ayrton_senna
  • 1,021
  • 2
  • 15
  • 31

3 Answers3

16

That's the job for sed:

sed -e 'G;G;G;G;G' file

With awk:

nawk -vORS='\n\n\n\n\n\n' 1 file

Or shorter version:

awk 'ORS="\n\n\n\n\n\n"' file

or avoid setting ORS for each input line:

awk 'BEGIN{ORS="\n\n\n\n\n\n"};1' file
cuonglm
  • 150,973
  • 38
  • 327
  • 406
1

Another one , with printf

cat file.txt | xargs printf "%s\n\n\n\n\n"

To output that to a file

(cat file.txt | xargs printf "%s\n\n\n\n\n") > out.txt

Sergiy Kolodyazhnyy
  • 16,187
  • 11
  • 53
  • 104
0

You might want to use nl for this, too. It comes to my mind because when I do stuff like that I often find it useful to retain the original line-numbers.

eval "nl -ba -s'$(printf "\n\n\n\n\n'")" <infile

Also pr is spec'd for the -doublespace argument - which will double all newlines in input on output.

But sed's good, too.

mikeserv
  • 57,448
  • 9
  • 113
  • 229