: ########################################################################## # Shellscript: xtod - UNIX to DOS text file conversion # Author : Heiner Steven # Category : File Conversion # SCCS-Id. : @(#) xtod 1.2 16/11/14 ########################################################################## # Description # Replaces "LF" end-of-line marker (ASCII 10) with "CR LF" sequence # (ASCII 13 10). # Does not handle DOS end-of-file character CTRL-Z (ASCII 26). ########################################################################## PN=`basename "$0"` # Program name VER='1.2' Usage () { echo >&2 "$PN - UNIX to DOS text file conversion, $VER usage: $0 [file ...]" exit 1 } Msg () { for MsgLine do echo "$PN: $MsgLine" >&2 done } Fatal () { Msg "$@"; exit 1; } AddCR() { 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 AddCR else trap 'rm -f "$Tmp"' 0 trap "exit 2" 1 2 3 15 for file do echo >&2 "$file" Tmp=$file.$$ if AddCR "$file" > "$Tmp" then mv "$Tmp" "$file" || error=1 else error=1 Msg "ERROR: could not process file: $file" fi done fi exit $error