[techtalk] vi technique for dos2unix
Sean McAfee
mcafee at umich.edu
Thu May 4 12:27:28 EST 2000
Amanda Babcock <alb at quandary.org> wrote:
>On Wed, 3 May 2000, Sean McAfee wrote:
>>Allow me to suggest a much shorter alternative:
>>perl -i -pe 'tr/\015//d' file1 file2 ...
>Actually, the key part of Christian's script is even shorter:
>>> then cat $1 | tr -d "\015" > $1
>In other words, cat file1 | tr -d "\015" > file2. I think this is shorter
>than your perl solution.
Perhaps I didn't make myself clear, but the above Perl one-liner converts
each filename that follows and saves the new file under the original filename.
It doesn't read from file1, strip the carriage returns, and save the output
to file2; it converts each file *in-place* without the need for a temporary
output file. (At least, this works on OSen that support unlinking an open
file which is then held open until closed, which excludes at least Windows
95 to my knowledge.)
If you had a directory with a hundred DOS files, you could convert them all
at once by cd-ing to that directory and doing this:
perl -i -pe 'tr/\015//d' *
The shell script would need to be invoked a hundred times.
>The rest of the script was error-checking, which neither of the above
>one-liners does.
No *explicit* error checking. Plenty of implicit checking. Try this:
perl -i -pe 's/foo/bar/' non-existent-file
Or this:
touch tempfile
chmod u-rwx tempfile
perl -i -pe 's/foo/bar/' tempfile
--
Sean McAfee | GCS d->-- s+++: a27 C++ US+++ P+++$ L++ E- W+ N++ |
| K w--- O? M- V-- PS+ PE Y+ PGP?>++ t+() 5++ X R+ | mcafee@
| tv+ b++ DI++ D+ G e++ h r---* y+>++ | umich.edu
More information about the Techtalk
mailing list