1. Introduction tr is used to convert or delete a piece of text. tr is the abbreviation of translate, and its function in English is: translate or delete characters. All the functions of tr can be completed by sed, and tr can be regarded as a minimalist implementation of sed. 2. Format tr [OPTION]... SET1 [SET2] 3. Options -c, -C, --complement: Delete characters other than character set <character set1> or convert them to the last character in character set <character set2> (if you specify multiple characters). See Example 6. -d, --delete: Delete the string SET1 in the information. -s, --squeeze-repeats: Squeeze repeated characters and keep only one. --help: Display help information. --version: Display version information. 4. Examples (1) Change all lowercase characters in the information output by last to uppercase characters. last|tr '[az]' '[AZ]' //or last|tr [az] [AZ] (2) Delete the colon ":" from the information output by /etc/passwd. cat /etc/passwd | tr -d ':' (3) Convert DOS files into Unix files. cat /etc/passwd | tr -d '\r' (4) Delete blank lines cat file | tr -s "\n" > new_file (5) Replace "abc" that appears in the file with "xyz". cat file | tr "abc" "xyz" > new_file Note: Here, all occurrences of the letter "a" in the file are replaced with the letter "x", the letter "b" is replaced with the letter "y", and the letter "c" is replaced with the letter "z", rather than replacing the string "abc" with the string "xyz". (6) Delete and replace characters outside the specified character set. //Replace characters outside the specified character set [b3335@MIC ~]$ echo alv blv|tr -c 'lv ' "x" xlv xlv //Delete characters outside the specified character set [b3335@MIC ~]$ echo alv blv|tr -cd 'lv' lvlv The above is the detailed content of the use of Linux tr command. For more information about Linux tr command, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: WeChat applet to determine whether the mobile phone number is legal example code
>>: Summarize several common ranking problems in MySQL
background Flex layout achieves alignment and spa...
This article describes how to install MySQL 5.7 f...
When developing a Vue project, you often need to ...
Table of contents 1. Rendering 2. Bind data and a...
Table of contents 1. child_process 2. Command exe...
The problem that MYSQL5.7.17 cannot connect under...
This article shares the specific code of Javascri...
Basic Introduction Features Flexbox is a CSS disp...
CSS: Copy code The code is as follows: *{margin:0;...
Preface When sharing a page, you hope to click th...
introduction During the front-end project develop...
This is a pretty cool feature that makes web page...
Learning objectives: Learn to use Windows system ...
What is pip pip is a Python package management to...
You may have set a MySQL password just now, but f...