This article describes a shell script for uppercase and lowercase conversions, learning the use of commands such as TR, awk, and sed. Have a friend in need of reference under
The following script allows you to convert directories or file uppercase and lowercase letters as follows:
Copy Code code as follows:
#!/bin/sh
#edit by Www.jb51.net
# [: Upper:] [A-z]
# [: Lower:] [A-z]
# [:d igit:] [0-9]
# [: Alnum:] [0-9-A-A-z]
# [: space:] spaces or t a b keys
# [: Alpha:] [A-z]
# TR
for f in *
do
echo $f | TR "[: Upper:]" [: Lower:] "
done
#awk
#把当前目录下的所有小写文件名都改为大写文件名.
ls | awk ' {printf ("mv%s%SN", $, ToUpper ($)) | " Sh "} '
#把当前目录下的所有大写文件名都改为小写文件名.
ls | awk ' {printf ("mv%s%SN", $, ToLower ($)) | " Sh "} '
#sed
file= "Test.txt"
Cat $file | Sed ' y/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/'
Code Description:
Method 1, using the TR command.
Method 2, Method 3, using the AW command.
Method 4, using the cat sed command.
For the test file Test.txt, its original content, as shown in the following figure:
By Method 4, the contents of the conversion are all capitalized, as shown in the following figure: