Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REMOVING ^M FROM SRC FILE

Status
Not open for further replies.

hubud

Instructor
Oct 18, 2002
123
GB
Hi,

I'm trying to remove some trailing ^M from the end of each line in a file. It works when i print to STDOUT but when I direct the output to another file all the ^M's return. The simple code is:

#!/usr/local/perl5.6.1/bin/perl


open SRC, "<create_dynamic_scripts.sql" or die "Can't open SRC\n";
open STDOUT, ">create_dynamic_scripts.sql.clean" or die "Can't open TGT\n";
while (<SRC>) {

$_ =~ s/\^M$//;
print "$_";

}

close SRC or die "Can't close SRC\n";
close STDOUT or die "Can't close TGT\n";


any ideas?

cheers

simmo
 
Most *nix systems have the dos2unix utility installed. Just type "dos2unix filename" on the command line and you're set.
 
Isn't this what chomp is designed to deal with? Or am I just being dense?

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top