DOS-to-UNIX file conversion

0
701

Using Perl:
# WARNING! For UNIX only! Do not use with ActivePerl in MSYS shell on Windows!
# (Returns error message and file is deleted.)

perl -pi -e 's/\r\n/\n/g' filename

Using sh or bash:
Works fine even in MSYS shell on Windows.

#tr -d '\r' < original_filename > new_filename

(Note that the “<” and “>” must be typed for this command to work).

The same replacing technique can of course be applied to any string.
The following one-liner changes the ‘cellpadding’ value from 4 to 2 in all files in the current directory where the ‘cellpadding’ value is 4, and the ‘cellspacing’ value is 1:

# WARNING! For UNIX only! Do not use with ActivePerl in MSYS shell on Windows!
# (Returns error message and deletes ALL files in directory!)

perl -pi -e  's/cellpadding=\"4\" cellspacing=\"1\"/cellpadding=\"2\" cellspacing=\"1\"/g' *

Originally posted 2016-03-12 03:36:50.

LEAVE A REPLY

Please enter your comment!
Please enter your name here