Text file cleanup

Hi there,

i do get some text files that i'd lile to clean them up based on following rule: if a line starts with " then remove return (new line, carriage return) before ".

Example, my input text file

line 1
line 2
"line 3

I'd like this to come as

line 1
line 2line3

How can i achieve this?

$ awk '/^"/ { print L substr($0,2) ; L="" ; C=0; next } { if(C) print L ; L=$0 ; C=1 } END { if(C) print L }' inputfile

line 1
line 2line 3

$

I'll need more details on the newline carriage return thing before I can account for that. are ALL your lines \r\n or just some?

1 Like

thank you for your reply, that does work nicely.
after runnign your command i realized that some of my lines start with a space before ", some with ", can you please update the command so it includes lines that start with space followed by "

Thank you!

Not sure if this will work on more sophisticated file structures:

awk '{sub (/\n"/, _)} 1' RS= file
line 1
line 2line 3

For your new request, try

awk '{gsub (/\n *"/, _)} 1' RS= file
1 Like

thank you both for your help!