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


line 1
line 2
line 3


line 1

line 2

line 3    


Solaris 5.10, nawk or sed.


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
  • Or this variant: awk 'ORS="\n\n\n\n\n\n"' – Janis Jun 6 '15 at 7:55
  • Or this variant: sed 's/$/\n\n\n\n\n/g' file – Dani_l Jun 7 '15 at 14:56
  • @Dani_l: It only works in GNU sed – cuonglm Jun 7 '15 at 14:57
  • @cuonglm didn't know that, thanks for the info. Which part is gnu specific? the \n in replacement? – Dani_l Jun 7 '15 at 14:58
  • @Dani_l: Yes, \n in the replacement part of s///. – cuonglm Jun 7 '15 at 15:00

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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.