Posted by: MikeLaverick
when relevant content is
added and updated.
Be careful how you use WinSCP to transfer files. If you transferring a script or a text file – be sure to set Text as your option
Failure to do so could potentially corrupt the file. If it’s a script it will return what appear to be syntax errors. This corruption is very easy to spot every end the line will have ^M at the end of it.
If you do copy a file which results in corruption – and its your only copy – this could be deeply annoying. Fortunately, there is a script to correct this if it a happens.
# Du.sh: DOS to UNIX text file converter.
if [ -z "$1" ]
echo “Usage: `basename $0` filename-to-convert”
CR=’\015′ # Carriage return.
# 015 is octal ASCII code for CR.
# Lines in a DOS text file end in CR-LF.
# Lines in a UNIX text file end in LF only.
tr -d $CR < $1 > $NEWFILENAME
# Delete CR’s and write to new file.
echo “Original DOS text file is \”$1\”.”
echo “Converted UNIX text file is \”$NEWFILENAME\”.”
I saved this as correct.sh
sh correct.sh problemfile.sh
When you run this script it will report:
Original DOS text file is “problemfile.sh”.
Converted UNIX text file is “problemfile.sh.unx”.
and you annoying ^M will be goneâ€¦.
I would like to thank Nicke of http://www.alt64.se/vmvbu/ for this script – he didn’t write it – it just seems to be “out there”