Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Tr command for shell learning

Shulou Source: shulou.com Published: 2022-06-01 07:52:15 10月25日 Update

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

Tags: Characters strings commonly used commands files examples input individual parameters variables sentences just uppercase character set lowercase sequence case standard abbreviation but Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn NVidia Docker MySQL