In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to convert uppercase and lowercase characters in Linux", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to convert uppercase and lowercase characters in Linux" article.
Environment
Centos7
Use tr
If you have a string to make sure it is all uppercase, simply replace it with the tr command:
[root@localhost ~] # echo "Hello World" | tr [: lower:] [: upper:] HELLO WORLD
The following is an example of using this command in a script, and you need to ensure that all text added to the file is uppercase to maintain consistency:
#! / bin/bashread-p "Enter department name:" deptecho $dept | tr [: lower:] [: upper:] > depts
Switching the order to [: upper:] [: lower:] converts all uppercase characters to lowercase:
#! / bin/bashread-p "Enter department name:" deptecho $dept | tr [: upper:] [: lower:] > depts
You can also use "a murz" or "Amurz" to replace case.
#! / bin/bashread-p "Enter department name:" deptecho $dept | tr Amurz Amurz > > depts
The following functions are built into tr:
[: alnum:] all letters and numbers
[: alpha:] all letters
[: blank:] all blanks
[: cntrl:] all control characters
[: digit:] all numbers
[: graph:] all printable characters, excluding spaces
[: lower:] all lowercase characters
[: print:] all printable characters, including spaces
[: punct:] all punctuation marks
[: upper:] all uppercase characters
Use awk
You can use the toupper () and tolower () functions in awk to convert case. The following example is written in the text, converting the input from lowercase to uppercase:
#! / bin/bashread-p "Enter department name:" deptecho $dept | awk'{print toupper ($0)}'> > depts
The following example is written in the text, converting the input uppercase to lowercase:
#! / bin/bashread-p "Enter department name:" deptecho $dept | awk'{print tolower ($0)}'> depts uses sed
You can use the\ U & and\ L & functions in sed to convert case.
Using sed, convert lowercase to uppercase:
#! / bin/bashread-p "Enter department name:" deptecho $dept | sed's / [Amurz] /\ Ubland depts
Using sed, convert uppercase to lowercase:
#! / bin/bashread-p "Enter department name:" deptecho $dept | sed's / [Amurz] /\ Lawash depts above is about "how to convert uppercase and lowercase characters in Linux". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.