dos和unix文件格式转换

时间:2023-02-10 22:09:30
#!/bin/bash

#--------------------------------------
#本脚本能实现将file由dos转换为unix,也可以实现由unix转换为dos
#日期:2016/7/24
#作者:齐豪
#--------------------------------------

Usage(){
echo "The first, filename should be 5.dos2unix.sh or 5.unix2dos.sh"
echo "and usage: ./5.dos2unix.sh [FileName]"
exit
}

dosToUnix(){
sed -i 's/\r//' $1
exit
}

unixToDos(){
sed -i 's/$/&\r/g' $1
exit
}

if [ -z $1 ]; then
Usage;
elif [ $0 = "./5.dos2unix.sh" ]; then
dosToUnix $1;
elif [ $0 = "./5.unix2dos.sh" ]; then
unixToDos $1;
else
Usage;
fi