: ########################################################################## # Shellscript: dtox - DOS to UNIX text file conversion # Author : Heiner Steven # Category : File Conversion # SCCS-Id. : @(#) dtox 1.2 16/11/14 ########################################################################## # Description # Replaces "CR LF" sequences with "LF" end-of-line. # Does not handle DOS end-of-file character CTRL-Z (ASCII 26). ########################################################################## PN=`basename "$0"` # Program name VER='1.2' Usage () { echo >&2 "$PN - DOS to UNIX text file conversion, $VER usage: $PN [file ...]" exit 1 } Msg () { for MsgLine do echo "$PN: $MsgLine" >&2 done } Fatal () { Msg "$@"; exit 1; } # Delete carriage-return character (ASCII 13, ^M) from input DeleteCR() { sed 's/ $//' "$@" } set `getopt h "$@"` || Usage [ $# -lt 0 ] && Usage # "getopt" detected an error while [ $# -gt 0 ] do case "$1" in # your flags here --) shift; break;; -h) Usage;; -*) Usage;; *) break;; # First file name esac shift done error=0 if [ $# -le 0 ] then # Read standard input, write standard output DeleteCR else trap 'rm -f "$Tmp"' 0 trap "exit 2" 1 2 3 15 for file do echo >&2 "$file" Tmp=$file.$$ if DeleteCR "$file" > "$Tmp" then mv "$Tmp" "$file" || error=1 else error=1 Msg "ERROR: could not process file: $file" fi done fi exit $error