0

I have a text file which some of the entries look like this:

"Hello, my name is

George. Its very nice to meet you"

and I would like to run an SED or AWK command that gives me the following result:

"Hello, my name is George. Its very nice to meet you"

I know I can remove blank lines with SED by running:

sed '/^\s*$/d' 

That command only removes the blank line but it does not join the string as shown above.

Thanks

gboffi
  • 22,939
  • 8
  • 54
  • 85
Leonus
  • 11
  • 2

2 Answers2

2

I would use awk:

awk 'BEGIN{RS="\n\n";ORS=" "}1' file

The command is using two newlines (a blank line) as the input separator and a space as the output record separator.

1 is an awk idiom. It will always evaluate to true which makes awk print every record.


Btw, if your blank lines may contain whitespace, change the command to:

awk 'BEGIN{RS="\n[[:space:]]*\n";ORS=" "}1' file
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • Thank you so much for your response. It did work with a test file I created but it does not work on the file I need to fix. Perhaps there are some garbage characters in the supposedly empty lines? I do not see any. – Leonus Mar 21 '16 at 22:10
  • Probably the file you are working on is from Windows? – hek2mgl Mar 21 '16 at 22:13
0

Go menu -> Edit -> Line operations - Choose "Remove Empty Lines" in Notepad ++

in one click all extra lines get removed :)

Lakshay Sharma
  • 1,347
  • 12
  • 13