Uppercase and lowercase converted shell script code _linux Shell

Source: Internet
Author: User
Tags lowercase
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-z]
# [: Space:] spaces or t a b keys
# [: Alpha:] [A-A-z]
# TR
For f in *
Todo
echo $f | TR "[: Upper:]" [: Lower:] "
Done
#awk
#把当前目录下的所有小写文件名都改为大写文件名.
ls | awk ' {printf ("mv%s%s\n", $, ToUpper ($)) | " SH "}"
#把当前目录下的所有大写文件名都改为小写文件名.
ls | awk ' {printf ("mv%s%s\n", $, 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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.