File indexing completed on 2024-12-08 05:05:48

0001 #!/bin/sh
0002 #
0003 # Copyright (c) 2014, Michal Policht. This file is dually licensed under terms of 
0004 # either WTFPL or BEER-WARE LICENSE. You may obtain the copy of WTFPL or BEER-WARE
0005 # LICENSE by googling it. NO WARRANTY. YOU WILL PAY ALL COSTS FOR ANY REPAIRS.
0006 #
0007 # Simple script to remove carriage return character (Windows style new line).
0008 #
0009 # usage: rmcr.sh file
0010 # example: rmcr.sh xfile
0011 #
0012 # parameters:
0013 # file - file.
0014 #
0015 # required tools: sh, tr, mv, stat, grep, cut, touch.
0016 
0017 
0018 function usage()
0019 {
0020     echo "usage: $0 file"
0021 }
0022 
0023 file=$1
0024 
0025 if [ ! -e $file ]; then
0026     echo $file "does not exist"
0027         exit 1
0028 fi      
0029 
0030 if [ $# -lt 1 ]; then
0031     echo "error: too few arguments"
0032     usage
0033     exit 0
0034 fi
0035 
0036 echo $file
0037 timestamp=`stat $file | grep 'Modify: ' | cut -d ' ' -f 2,3,4`
0038 <$file tr -d '\r' > $file.tr
0039 mv $file.tr $file
0040 touch -md "$timestamp" $file
0041