In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "Linux command line how to convert case characters to content". In daily operation, I believe many people have doubts about how to convert case characters to content on Linux command line. Xiaobian consulted all kinds of materials and sorted out simple and easy to use operation methods. I hope to answer your doubts about "Linux command line how to convert case characters to content"! Next, please follow the small series to learn together!
If you have a string that you want to make sure is all caps, simply replace it with tr:
[root@localhost ~]# echo "Hello World" | tr [:lower:] [:upper:]HELLO WORLD
Here is an example of using this command in, making sure that all text added to the file is capitalized for consistency:
#!/ bin/bashread -p "Enter department name: " deptecho $dept | tr [:lower:] [:upper:] >> depts
Switching the order to [:upper:] [:lower:] converts all upper-case characters to lower-case:
#!/ bin/bashread -p "Enter department name: " deptecho $dept | tr [:upper:] [:lower:] >> depts
You can also use "a-z" "A-Z" to replace case.
#!/ bin/bashread -p "Enter department name: " deptecho $dept | tr a-z A-Z>> 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 upper-case characters
use awk
In awk, you can use the toupper() and tolower() functions to convert case.
The following example is written in text, converting lowercase to uppercase:
#!/ bin/bashread -p "Enter department name: " deptecho $dept | awk '{print toupper($0)}' >> depts
The following example is written in text, converting the input capital to lowercase:
#!/ bin/bashread -p "Enter department name: " deptecho $dept | awk '{print tolower($0)}' >> depts
using the sed
The\U& and\L& functions can be used in sed to convert case.
Use sed to convert lowercase to uppercase:
#!/ bin/bashread -p "Enter department name: " deptecho $dept | sed 's/[a-z]/\U&/g' >> depts
Use sed to convert uppercase to lowercase:
#!/ bin/bashread -p "Enter department name: " deptecho $dept | sed 's/[A-Z]/\L&/g' >> depts
summary
There are many ways to replace upper and lower case letters in linux, and you can choose a command you can remember to use.
At this point, the study of "how to convert case characters from Linux command line" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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.