[Techtalk] real life kewl text-processing and regexps
sampleswanted
H. Peter Anvin
hpa at zytor.com
Sun Jan 11 12:49:29 EST 2004
dominik.schramm at gmxpro.net wrote:
> "Kathryn Hogg" <kjh at flyballdogs.com> writes:
>
>>Brenda Bell said:
>>
>>>A command I use a lot is:
>>>
>>> cat dos-file.txt | sed -e '1,$s\^M\\g' >linux-file.txt
>>
>>I use dos2unix for those conversions.
>
>
> dos2unix is not always installed. When I have to
> convert DOS to Unix line endings on such systems
> (and I don't want to/can't install dos2unix) I use
>
> perl -pi -e 's/\r\n/\n/' filename
>
> ("p" means loop over input lines; "i" means in-place editing;
> "e" means use script from command line)
>
Or using strictly standard Unix tools (in case you have to deal with
primitive systems which don't come with Perl installed):
tr -d '\r' < filename > filename.out
(This does kill single \r's as well, though.)
-hpa
More information about the Techtalk
mailing list