In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 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 case in the Linux command line", so the editor summarizes the following contents, detailed contents, 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 case in the Linux command line" article.
Tr command
Tr (translate) is one of the simplest case conversion commands that can be used on the command line or script. For example, if you want a string of strings to be all uppercase, you can do this with a command like this:
$echo hello alvin | tr [: lower:] [: upper:] HELLO ALVIN
The following is an example of how the command is applied to a script, where all the contents written to the file depts will be in uppercase format:
$echo "Enter department name:" | tr [: lower:] [: upper:] > depts
Changing the order of the above command to [: upper:] [: lower:] will get the opposite result, and all entered letters will be lowercase:
$echo "Enter department name:" | tr [: upper:] [: lower:] > depts
You can use Amurz Amurz instead of [: upper:] [: lower:] to achieve the same effect:
$echo "Enter department name:" | tr Amurz Amurz > > deptsawk command
The awk command performs case conversion with the options toupper and tolower. The case conversion of the script described above can be done with this command as follows:
$echo "Enter department name:" | awk'{print toupper ($0)}'> > depts
The above is converted to uppercase letters, and the following is how to convert to lowercase letters:
$echo "Enter department name:" | awk'{print tolower ($0)}'> > deptssed command
The sed (stream editor) command also does a good job of case conversion, and the following command can achieve the same effect as the first two commands:
$echo "Enter department name:" | sed's / [a murz] /\ Ublink Universe g'> depts
To do the reverse conversion, simply replace U in the above command with L and [a murz] with [Amurz]:
$echo "Enter department name:" | sed's / [Amurz] /\ Lawyer _ depts
Both the awk and sed commands can convert the case of the entire document content to lowercase, so if you need to convert the entire document content to lowercase, you can output the contents of a file to the screen in lowercase with the following command:
$awk'{print tolower ($0)} 'depts
The results are as follows:
Enter department name:financebillingbookkeeping
Note that this result only converts what is printed on the screen to lowercase, and the uppercase letters in your own document remain unchanged, as you can see by using the cat depts command. If you want to change the case of the document exactly, you can do it with the following command:
$awk'{print tolower ($0)} 'depts > depts-$ mv depts- depts
The sed command can perform the same function as awk, but with a slight difference in usage, it is used as follows:
$sed's / [Amurz] /\ Lhasa depts only uppercase the initials
Capitalize only the first letter of each word in a string, which can be done with the following command:
$echo design\ & engineering | sed-e "s /\ b\ (.\) /\ u\ 1zag" Design & Engineering
The above command allows only the first letter to be capitalized and the other letters unchanged.
Make sure only the initials are capitalized.
When you need to do this with a large number of text, such as displaying a large number of people's names in the correct format, what you need to do becomes a little more difficult. Here are two ways to accomplish this task:
Complete with the sed command
To ensure that the results are correct, a more complex sed command format is required:
$echo design\ & ENGINEERING | sed's /\ b\ ([[: alpha:]]\)\ ([[: alpha:]] *\)\ b /\ u\ 1\ L\ 2/g'Design & Engineering is done in python code
If you have python installed on your Linux, you can capitalize the text with the following command, and the python code is much easier to understand than the regular formula of the sed command above:
$echo-n "design & engineering" | python3-c "import sys; print (sys.stdin.read (). Title ())" Design & Engineering above is about "how to convert case in Linux command line". 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.