How to insert multiple blank lines after every line
20,282
Solution 1
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
Solution 2
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
Related videos on Youtube
Author by
ayrton_senna
Updated on September 18, 2022Comments
-
ayrton_senna over 1 year
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
orsed
.-
don_crissti almost 9 years
-
-
Janis almost 9 yearsOr this variant:
awk 'ORS="\n\n\n\n\n\n"'
-
Dani_l almost 9 yearsOr this variant:
sed 's/$/\n\n\n\n\n/g' file
-
cuonglm almost 9 years@Dani_l: It only works in GNU sed
-
Dani_l almost 9 years@cuonglm didn't know that, thanks for the info. Which part is gnu specific? the \n in replacement?
-
cuonglm almost 9 years@Dani_l: Yes,
\n
in the replacement part ofs///
. -
Peter.O almost 9 years
awk 'ORS="\n\n\n\n\n\n"'
may be shorter (good for golfing, and handy-ish for quick one-offs), but it is unnecessarily setting a variable for every record it processes. -
cuonglm almost 9 years@Peter.O: Good point. Updated.