You can think of tr as an (extremely) simplified variant of sed: it can replace another character with one character, or it can completely remove some characters. You can also use it to remove duplicate characters. This is what all tr can do.
So why use tr instead of sed? Of course it is to make things simple. For example, if we want to replace all the letters that appear with the letter "z"; you can use tr az , this command is no doubt simpler than sed -es/a/z/g, especially in it When used in a script, the quotation marks are very confusing. In addition, when using tr, you can avoid writing annoying regular expressions.
Using tr is simple: use the symbolic notation given in the previous paragraph to replace all other characters that appear with one character. When you need to replace multiple characters, use a notation like this: tr abc xyz , which means to replace all the letters that appear with the letter “x”; a” replace all the letters with the letters “y”” ;b”, replace all letters "c” with the letters “z”. The number of characters listed in these two groups does not have to be equal.
You can also specify a range of characters. For example, tr a-z A-Z will replace all lowercase letters with corresponding uppercase letters (for example, it will convert "no smoking" into "NO SMOKING". This special technique is handy when you want to emphasize a part of the text being edited in the vi editor. Just press the Escape key, then press the :, then type 2,4!tr 'a-z' 'A-Z' and press the Return key. Now, the letters from line 2 to line 4 are converted to uppercase letters.
In addition, when someone sends you a text file created on a Mac OS or DOS/Windows
machine, you will find tr useful. If you do not save the file to use UNIX line breaks to indicate the end of line format, you will need to convert such files to native UNIX format, otherwise some command utilities will not process them properly. The end of the Mac OS ends with a carriage return character, and many text processing tools treat such a file as a single line. To correct this problem, you can use the following tips:
Mac -> UNIX: tr '\
' '\ ' < macfile > unixfile UNIX -> Mac: tr '\ ' '\\ r' < unixfile > macfile Microsoft DOS/Windows convention, where each line of text ends with a carriage return character followed by a newline character. To correct this problem, you can use the following command:
DOS -> UNIX: tr -d '\
' < dosfile > unixfile UNIX -> DOS: In this case, you need to use awk Because tr cannot insert two characters to replace one character. The awk command to be used is awk '{ print $0"\
" }' < unixfile > dosfile In addition, when you need to do some simple finishing work on the text file (such as using tr -d '\\t' to remove the system When you use tr -s ' ' to remove extra spaces, or use tr -d '\ ' to combine separate lines into a single line, you will need to use tr. Again, you can use all of these commands in vi; just remember: add the line range and exclamation point (!) you want to process before the tr command, such as 1, $!tr -d '\\t' (dollar sign) Shown in the last line).
Requirement Description Set SNAT policy using iptables Make hosts on 192.168.100.0/24 network segmen
Engaged in two years WindowsClient development, what multi-threading, multi-process development, ha
Here is a way for you to quickly find a large file in the system. Recently received a users report,
This article describes the solution when encountering is not in the sudoers file during Linux use. W
How to check HTTP traffic on Linux
Access Control for Files under Linux
In linux, using reaver to crack the wireless wifi password download and use method
Linux modify user group method
Microsoft's release of Windows8 makes the Linux desktop operating system a step closer to us.
Set disk quotas for Linux MySQL databases
Analysis of Linux system computer crash causes
Tutorial to turn off SELinux features in Linux
Easy to adjust win7 partition in just three steps
Win10pc mobile phone terminal function
Kingsoft Internet Security set up a regular anti-virus graphic tutorial
Linux operating system mounts U disk and hard disk drive problem
Win 8 is priced below or below Win 7
Detecting the LCD monitor in the WinXP system
Change the access of the remote login windows system default port 3389
Win2003 system acceleration four skills