2

This is what I type and the output I get:

$ cat helloworld.txt

Hello World!
I'm Kanladaporn Sirithatthamrong
6480952

But this is what I want an output to be:

Hello World!

I'm Kanladaporn Sirithatthamrong

6480952

What should I do? Any suggestions please?

2
  • 2
    Your example does not show a blank line after each line. I assume that is what you want.
    – Jos
    Sep 29 at 13:02
  • Your title does not match the question. Do you want to insert a blank line after each line in text file? Sep 29 at 13:03

4 Answers 4

10

Use pr:

$ pr -Td helloworld.txt
Hello World!

I'm Kanladaporn Sirithatthamrong

6480952

$

From man pr:

   -d, --double-space
          double space the output

   -T, --omit-pagination
              omit page headers and trailers, eliminate any pagination by form feeds set in input files
7

You can use sed:

sed G helloworld.txt

To only add newlines when there isn't already a blank line, use:

sed '/^$/d;G' helloworld.txt

Reference: Handy one-liners for SED

1

Change the output record separator of awk to two newlines instead of the default one:

awk 'BEGIN { ORS = "\n\n"} { print }' helloworld.txt
1
  • You could also shorten this to awk -v ORS='\n\n' '1' helloworld.txt
    – terdon
    Sep 30 at 17:25
1
awk '{print;print ""}' helloworld.txt

Your Answer

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