Search code examples
awkunix-text-processing

replace new line with a space if next line starts with a word character


I've large text file that looks like

some random : demo text for
illustration, can be long

and : some more

here is : another
one

I want an output like

some random : demo text for illustration, can be long
and : some more
here is : another one

I tried some strange, obviously faulty regex like %s/\w*\n/ /g but can't really get my head around.


Solution

  • With your shown samples, please try following awk code. Using RS(record separator), setting it nullify. This is based on your shown samples only.

    awk -v RS="" '{$1=$1} 1' Input_file