Search code examples
linuxbashunixsedcarriage-return

How to delete newline and character at the start of line using Bash?


I need to delete a newline with exact character at the beginning of the line.

For example, I have new.txt file which contains the following lines:

"AAA"AAA
"BBB
"""BBB
"CCC"CCC

Expected result is:

"AAA"AAA
"BBB"BBB
"CCC"CCC

I tried using sed but it is not working.

sed -i -e 's/\n"""/"/g' new.txt

Please help me to solve this.


Solution

  • With Perl.

    perl -i -0777pe 's/\n"""/"/' new.txt
    

    Output to new.txt:

    "AAA"AAA
    "BBB"BBB
    "CCC"CCC