Could you do something like this
#!/usr/bin/perl -w
@index = `cat ./index.html`; #quick cheat to getting the file into memory
foreach (@index) { #foreach line in the arrary
$_ =~ s/^M//g; # 's'ubstitute ^M with blank char
print ("$_"); # print it back out HOPEFULLY
without the ^M
}
exit();
I hope your mail client didn't "word warp" the hell out of that.
Anyways here is how it works
#!/usr/bin/perl -w
$string = "This is a string, and has a BAD word in it";
print ("$string\n");
$string =~ s/BAD/GOOD/g;
print ("$string\n");
exit();
The output should be
This is a string, and has a BAD word in it
This is a string, and has a GOOD word in it
the magic line is
$string =~ s/BAD/GOOD/g;
The '$string' is a string, a peice of text
I don't know the techinal name for the '=~' part, it is "kinda" like a equal
sign, but you can determine truth by reg exps and such
the 's' part is important, it stands for substitution
the first '/' starts the reg exp
'BAD' is the char or string or reg exp you wish to get replace
the second '/' is a seperater
the 'GOOD' is what you want to replace 'BAD' with
the last '/' is the closing of the reg exp
the 'g' tells stands for global. If it finds 'BAD' in the string 3334
times, it will replace it globally, all 3334 times. If you don't include
the 'g', it will only replace the first 'BAD' it find.
';' closes the statement.
The hard part is going to be finding the '^M' in the index.html, since this
is probably a control character, and they can be difficult to find.
If you copied this file over from a DOS/Windows machine though FTP, try
downloading (or uploading) it in FTP ASCII mode, your FTP client/server will
replace those for you. Also there is something called mtools (?) ms-dos
tools, which are basically C programs that convert DOS ASCII to Unix ASCII
and vis-versa. If you are having problems moving Windows files to Unix and
vis-versa, post back to the list with that subject I know there is someone
on the list that could help you with this. There are already programs out
there that will do this for you (if this is the problem), but I can't recall
their names just right now.
Check perl.org or cpan.org for more information on Perl.
Jack
----- Original Message -----
From: James Ng <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 10, 2000 2:17 PM
Subject: delete char
> hello:
>
> can somebody teach me how do i write a perl script to delete the
> character ^M in a file.
> for example, i have a file called index.html and i want to delete all the
> ^M characters in the file. Thank you.
>
>
> __________________________________
> James Ng
> Electrical, Computer Engineering
> Washington University in St. Louis
> http://students.cec.wustl.edu/~cn2
> (314)862-4353
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to [EMAIL PROTECTED]
> Please read the FAQ at http://www.linux-learn.org/faqs
>
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs