Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert uppercase and lowercase characters in Linux command line

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to convert uppercase and lowercase characters on the Linux command line". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to convert uppercase and lowercase characters on the Linux command line".

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

Use 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 is all the contents of the article "how to convert uppercase and lowercase characters on the Linux command line". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report