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

Tr command for shell learning

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

The tr command does not accept the specified file parameters, but only translates the standard input. Tr is the abbreviation of translate, that is, translation. It should be noted that it cannot translate sentences, only a single character.

First, define the variable:

[root@tong] # Achievement 1, pause 2, 3, 3, 4, 5

The following is an example of this command and its common options.

Example:

1. No option setting

[root@tong] # echo $A | tr','1 23 4 5 [root@tong] # echo $A | tr [2-4] [blightd] 1 tr [root@tong] # echo $A | tr "23"bc" 1 mineforce5 [root@tong] # echo $A | tr "23"bc" 1

Note that instead of replacing the string, replace "2" with "b" and "3" with "c".

Commonly used: lowercase-> uppercase

# tr [Amurz] [Amurz]

two。 The option "- s" removes all recurring character sequences, leaving only the first, that is, the recurring string is compressed into a single string.

[root@tong] # echo $A | tr-s','1 root@tong 2 echo 3 recorder 4 [root@tong] # echo $A | tr-s','12 3 4 5

3. Option "- d" to delete all input characters specified by the string.

[root@tong] # echo $A | tr-d "23" 1 tr 4 [root@tong] # echo $A | tr-d', '12345

Commonly used: delete'^ M 'characters from Windows files

# tr-d "/ r"

4. Option "- c" to replace the complement of the character set in the string, requiring the character set to be A S C I I.

[root@tong] # echo $A | tr-c [1-5]'%'1%% 2%% 3%% 4%% 5

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

Network Security

Wechat

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

12
Report