Search code examples
macossedline-breaks

sed - remove line break if line does not end on \"


I have a tsv.-file and there are some lines which do not end with an '"'. So now I would like to remove every line break which is not directly after an '"'. How could I accomplish that with sed? Or any other bash shell program...

Kind regards, Snafu


Solution

  • give this awk one-liner a try:

    awk '{printf "%s%s",$0,(/"$/?"\n":"")}' file
    

    test

    kent$  cat f
    "foo"
    "bar"
    "a long
    text with
    many many
    lines"
    "lalala"
    
    kent$  awk '{printf "%s%s",$0,(/"$/?"\n":"")}' f
    "foo"
    "bar"
    "a longtext withmany manylines"
    "lalala"