computing
  • 0

How To Remove Carriage Return (CRLF) Within Double Quotes

  • 0

How to remove Carriage Return (CRLF) within double quotes in a file. There are multiple CRLFs within double quotes. We are on Ubuntu 14.04.2 LTS. Can someone advice with awk or sed script.
Note: command should only remove Carriage Return within Double Quotes

message edited by covina

Share

1 Answer

  1. If I am understanding correctly, you want to find a CRLF within double quotes and then remove just the CR. This perl script does that:

    #!/usr/bin/perl -w

    # this script finds a CRLF between double quotes and only removes the CR
    open FILE, “./data.txt” or die “Error message here: $!”;

    while (<FILE>) {
       chomp;
       my $newline = $_;
       $newline =~ s/"^M^L"/"^L"/g;
       print "$newline\n";
    }
    close (FILE);
    

    # be advised that in the script above ^M and ^L are actual control-M and control-L characters. To create them in vi press the control-v key combination and press control-m. Repeat the same process for control-L

    Or if you just want a perl one-liner to do the job:

    perl -wpl -e ‘s/”^M^L”/”^L”/g;’ data.txt > newdata.txt

    Let me know if you have any questions.

    message edited by nails

    • 0