Loading ...
Sorry, an error occurred while loading the content.

Re: [linux] M$ Text - ^M

Expand Messages
  • John Hogan
    ... howard i don t know about a filter , but what follows is a perl script that i borrowed , rewrote, and have been using for years and years on hundreds of
    Message 1 of 3 , Jun 30, 2001
    • 0 Attachment
      >I know there is a filter which will remove the "^M"s from line ends of M$
      >derrived text but I can't remember what it is nor can I seem to find
      >it. Please help if you know.

      howard

      i don't know about a 'filter', but what follows is a perl script that i
      'borrowed', rewrote, and have been using for years and years on hundreds of
      servers... you're welcome to it...

      ps - yorkshire is wonderful... i haven't been for about ten years - york
      should be the capital of the world ;-)

      - hogan

      perl script follows
      ***********************************
      #!/usr/bin/perl
      #
      # perl scriptlet to strip out '^M' chars
      # from M$ Windoze generated files
      #
      # usage:
      # rmcr <filename>
      #
      # john hogan
      # baywave media
      # john@...
      #
      $filename = $ARGV[0];

      if ($filename eq '') {
      print "usage: rmcr filename\n";
      exit(0);
      }

      # Verify that the file exists.
      unless (-e $filename) {
      print "Sorry, file not found '$filename'.";
      exit(1);
      }

      # Read in the file.
      open(F,$filename) or die "$! \'$filename\'";
      @lines = <F>;
      close(F);

      # Remove the ^M characters.
      $bytes_before = (-s $filename);
      open(F,">$filename") or die "$! \'$filename\'";
      foreach (@lines) {
      s/\015//;
      print F;
      }
      close(F);
      $bytes_after = (-s $filename);

      # Do some math and print a result to the user.
      $bytes_removed = ($bytes_before - $bytes_after);
      print "Done. $bytes_removed characters removed.\n";
      exit(0);
      *****************************
    Your message has been successfully submitted and would be delivered to recipients shortly.