> -----Original Message-----
> From: Booher Timothy B 1stLt AFRL/MNAC
> [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 05, 2001 9:27 AM
> To: [EMAIL PROTECTED]
> Subject: SIMPLE SCRIPT TO REMOVE ALL SPACE FROM THE ENDS OF LINES
> 
> 
> 
> I am looking for a simple way to go through my text file and 
> remove all
> spaces from the ends of lines. I have a feeling that this is 
> real easy, but
> don't know what function is best: does chomp do this?

chomp() removes the line-terminator (defined in the variable $/,
but typically "\n"). 

A one-liner for removing whitespace from the end of each line is:

   perl -p -e 's/\s+$//' myfile.txt

\s above will match all whitespace (spaces, tabs, form feeds). To 
match only spaces, use a blank instead of \s

You can add the -i option to update myfile.txt in place. 
(See perldoc perlrun for more details on -i)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to