The tr command reads data from the standard input device. After string translation, the result is output to the standard output device.
Syntax
Tr [-cdst] [-- help] [-- version] [first character set] [second character set]
Tr [OPTION]… SET1 [SET2]
Parameter description:
- -C, -- complement: specifies the inverse character. That is, the part that meets SET1 is not processed, and the rest of the non-conforming part is converted.
- -D, -- delete: delete command characters
- -S, -- squeeze-repeats: reduces the number of consecutive duplicate characters to a specified single character.
- -T, -- truncate-set1: cut SET1 to specify a range to make it equal to SET2 set length
- -- Help: Displays program usage information.
- -- Version: displays the version information of the program.
Character Set combination range:
- \ NNN octal characters NNN (1 to 3 are octal characters)
- \ Backslash
- \ A Ctrl-G ringtone
- \ B Ctrl-H return character
- \ F Ctrl-L line feed
- \ N Ctrl-J New Line
- \ R Ctrl-M Press enter
- \ T Ctrl-I tab key
- \ V Ctrl-X horizontal tab
- CHAR1-CHAR2: character range from CHAR1 to CHAR2 specified, range specified based on the ASCII code order, can only from small to large, not from large to small.
- [CHAR *]: this is a special setting for SET2. The function is to repeat the specified character until it is the same length as SET1.
- [CHAR * REPEAT]: this is also a special setting for SET2. The function is to REPEAT specified characters until the set number of REPEAT times (the REPEAT number is calculated in octal notation, starting with 0)
- [: Alnum:]: all letters, characters, and numbers
- [: Alpha:]: All letter characters
- [: Blank:]: all horizontal spaces
- [: Cntrl:]: all control characters
- [: Digit:]: all numbers
- [: Graph:]: All printable characters (excluding space characters)
- [: Lower:]: all lowercase letters
- [: Print:]: All printable characters (including space characters)
- [: Punct:]: all punctuation characters
- [: Space:]: all horizontal and vertical space characters
- [: Upper:]: all uppercase letters
- [: Xdigit:]: all hexadecimal numbers
- [= CHAR =]: all characters that match the specified character (the CHAR in the equal sign represents the character you can customize)
Instance
To convert all lowercase letters in the testfile to uppercase letters, run the following command:
Cat testfile | tr a-z A-Z
The content in the testfile file is as follows:
$ Cat testfile # original content of testfile
Linux networks are becoming more and more common,
But scurity is often an overlooked
Issue. Unfortunately, in today's environment all networks
Are potential hacker targets,
Fro0m tp-secret military research networks to small home LANs.
Linux Network Securty focuses on securing Linux in
Networked environment, where
Security of the entire network needs to be considered
Rather than just isolated machines.
It uses a mix of theory and practicl techniques
Teach administrators how to install and
Use security applications, as well as how
Applcations work and why they are necesary.
After the tr command is used for case-insensitive conversion, the following output is displayed:
$ Cat testfile | tr a-z A-Z # output after conversion
Linux networks are becoming more and more common, but scurity is often an overlooked issue. UNFORTUNATELY, in today's environment all networks are potential hacker targets, FROM TP-SECRET military research networks to small home lans.
Linux network securty focuses on securing linux in a networked environment, where the security of the entire network needs to be considered rather than just isolated machines.
IT USES A MIX OF THEORY AND PRACTICL TECHNIQUES TO TEACH ADMINISTRATORS HOW TO INSTALL AND
Use security applications, as well as how the applcations work and why they are necesary.
You can also use the [: lower] [: upper] parameter to convert the case. For example, run the following command:
Cat testfile | tr [: lower:] [: upper:]
The output result is as follows:
$ Cat testfile | tr [: lower:] [: upper:] # converted output
Linux networks are becoming more and more common, but scurity is often an overlooked issue. UNFORTUNATELY, in today's environment all networks are potential hacker targets, FROM TP-SECRET military research networks to small home lans.
Linux network securty focuses on securing linux in a networked environment, where the security of the entire network needs to be considered rather than just isolated machines.
IT USES A MIX OF THEORY AND PRACTICL TECHNIQUES TO TEACH ADMINISTRATORS HOW TO INSTALL AND
Use security applications, as well as how the applcations work and why they are necesary.