SUMMARY: sed question, remove ^M

From: Brehl, Blake (Blake.Brehl@anritsu.com)
Date: Mon Jul 29 2002 - 16:58:59 EDT


This list is great! 17 quick replies!!!! Thanks to:

9 reply's: :%s/<ctrl-v><ctrl-m>//g On the screen you
will see :%s/^M//g

Ashish Tripathi: cat file name | col -b > new file name

Phil Farrell: tr -d '\015' < infile > outfile
Lucas Carey: perl -i -pe 's/\r$//' [filename] or....
                        perl -i.orig -pe 's/\r$//' [filename] saves a copy
as filename.orig

Richard: strings windoze_file >> unix_file

Dan Price: :1,$s/.$//g

Roger Moody mwrite [-mntv] unixfile msdosfile

Fred Cassirer perl "unix2dos" script (below)

Thanks to all that replied!

Best Regards, Blake

Blake Brehl
Sr. DBA
Anritsu Company United States
Morgan Hill, CA

<<<from Fred Cassirer>>>
This perl script, I call "unix2dos" works. With
one line of change, it can be dos2unix, just remove the s/$/\015/; line in
stripcr:

Have fun.
-FredC

        #!/bin/perl
        my $verbose = 0;
        while ($_ = $ARGV[0], /^-/) {
                shift;
                last if /^--$/;
                /^-v/ && $verbose++;
        }

        foreach (@ARGV)
                    {
                    print "Dose^M'ing $_\n" if ($verbose);
                    stripcr($_);
                    }

        sub stripcr {
                    my ($file) = @_;

                    if (-T $file)
                        {
                        open(FILE,"<$file") || die "Can't open $file: $!";
                       open(TMP,">$file.$$") || die "Can't open $file.$$: $!";

                        while (<FILE>)
                            {
                            chop;
                            s/\015$//;
        # Remove the following line to create ^M stripped file, i.e.,
        # dos2unix instead of unix2dos
                            s/$/\015/;
                            print TMP "$_\n";
                            }
                        close(TMP);
                        close(FILE);
                        unlink "$file";
                        rename "$file.$$","$file";
                        }
                    else
                        {
                        print STDERR "Warning: $file appears to be binary,
no changes made\n";
                        }
        }

>>>ORIGINAL POSTING<<<
Hello, Admin's,
our better half over the pond has delivered a file that was edited with a
Windows based editor, which has left the "^M" characters (return of line?)
at the end of each line:
        Parent(s):^M
        spec :^M
        ^M
        History:^M
I've attempted several sed commands to remove these with no luck:
        :%s!{^M}!!g
        :%s!`^M`!!g
, but I'm sure I've seen this done. Can anyone help with the correct syntax?

This message is intended for the use of the individual/entity to whom it is addressed. This message may contain privileged information exempt from disclosure. If you are not the addressee, distribution or copying of this message, or dissemination of the information contained herein is strictly prohibited. If you should receive this message in error, please destroy it, or return to sender, Thank You



This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 10:48:47 EDT