Wednesday, August 10, 2011

UNIX script: transfer DOS file to UNIX file

/usr/bin/dos2unix -437 "$dosfile" $unixfile

or

tr -d '\r' < "$dosfile" > $unixfile

or

sed 's/^M$//' "$dosfile" > $unixfile

or

perl -pi -e 's/\r\n/\n/g' "$dosfile" > $unixfile

UNIX script: add new line at the end of file, if not exist

if [[ -n "`/bin/tail -1c $unixfile`" ]]; then
echo >> $unixfile
fi