"Linux" character conversion command tr

Source: Internet
Author: User

  TR (abbreviated by Traslate) can be used to delete text from a piece of information, or to replace text messages!

[Email protected] ~]#TR[-DS] SET1 ... Options and Parameters:-d: Delete the SET1 string from the message;-s: replace the duplicate characters! Example one: to Lastin the output information, all lowercase letters become uppercase characters: [[email protected]~]# Last|TR '[A-z]' '[A-z]'# In fact, there is no single quote that can be run, such as: " Last|TR[A-z] AZ] "Example two: Will/etc/passwdin the output information, the colon (:) delete [[email protected]~]#Cat/etc/passwd|TR-D':'example three: the/etc/passwdDump DOS to/root/passwd, and then the ^M sign Delete [[email protected]~]#CP/etc/passwd/root/passwd&& unix2dos/root/passwd[[Email protected]~]#file/etc/passwd/root/passwd/etc/passwd: ASCII text/root/passwd: ASCII text, with CRLF line Terminators <==is a DOS break [[email protected]~]#Cat/root/passwd|TR-D'\ r'>/root/passwd. linux# that \ r refers to a DOS-break character, for more characters, refer toMans TR[[Email protected]~]# ll/etc/passwd/root/passwd*-rw-r--r--1Root root1986Feb6  -: -/etc/passwd-rw-r--r--1Root root2030Feb7  the: -/root/passwd-rw-r--r--1Root root1986Feb7  the: $/root/passwd.

in fact, this command can also be written in the "formal notation" inside! Because he is also in the form of formal notation to replace the data! In the example above, use [] to configure a string of words! It's also often used to replace weird symbols in files ! For example, in the third example above, you can remove the ^m of a DOS file! This thing is quite useful! Believe it's the most troublesome thing to do with Linux & Windows systems! That is, the DOS will automatically add the ^m line at the end of each line! This time we can use this TR to remove the ^m! ^m can use \ r to replace it!

  References: http://vbird.dic.ksu.edu.tw/linux_basic/0320bash.php#pipe_4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.