当前位置: 技术问答>linux和unix
将一个文件中的英文字母全部转为大写字母
来源: 互联网 发布时间:2017-01-21
本文导语: #!/bin/bash while [ "$1" ] do if [ "$1"="-i" ] then infile="$2" echo $infile shift 2 echo $infile elif [ "$1"="-o" ] then outfile=$2 echo $outfi...
#!/bin/bash
while [ "$1" ]
do
if [ "$1"="-i" ]
then
infile="$2"
echo $infile
shift 2
echo $infile
elif [ "$1"="-o" ]
then
outfile=$2
echo $outfile
shift 2
echo $outfile
else
echo "Program $0 doesn't recognize option $1 "
fi
done
echo $infile
echo $outfile
tr a-z A-Z $outfile
#end
保存为upcase.
#./upcase -i a.txt -o d.txt |cat -n的时候显示如下:
1.a.txt
2.a.txt
3.d.txt
4.d.txt
5.d.txt
6.
不知道怎么回事,应该是infile变成了d.txt,outfile变成空了。
while [ "$1" ]
do
if [ "$1"="-i" ]
then
infile="$2"
echo $infile
shift 2
echo $infile
elif [ "$1"="-o" ]
then
outfile=$2
echo $outfile
shift 2
echo $outfile
else
echo "Program $0 doesn't recognize option $1 "
fi
done
echo $infile
echo $outfile
tr a-z A-Z $outfile
#end
保存为upcase.
#./upcase -i a.txt -o d.txt |cat -n的时候显示如下:
1.a.txt
2.a.txt
3.d.txt
4.d.txt
5.d.txt
6.
不知道怎么回事,应该是infile变成了d.txt,outfile变成空了。
|
#cat a.txt
topic.CSDN.net
#cat test.sh
#!/bin/bash
while [ "$1" ]; do
if [ "$1" == "-i" ]; then
infile="$2"
echo $infile
shift 2
echo $infile
elif [ "$1" == "-o" ]; then
outfile=$2
echo $outfile
shift 2
echo $outfile
else
echo "Program $0 doesn't recognize option $1 "
fi
done
echo $infile
echo $outfile
tr '[a-z]' '[A-Z]' $outfile
#./test.sh -i a.txt -o d.txt
a.txt
a.txt
d.txt
d.txt
a.txt
d.txt
#cat d.txt
TOPIC.CSDN.NET
|
直接用tr 命令不行吗
tr '[:lower:]' '[:upper:]' newfile
转换yourfile中的小写字母,转换结果写入文件newfile
tr '[:lower:]' '[:upper:]' newfile
转换yourfile中的小写字母,转换结果写入文件newfile
|
tr 'a-z' 'A-Z' 试试