A detailed description of TR usage in Linux

Source: Internet
Author: User


The TR command can replace, compress, and delete characters from standard input. It can literal a group of characters into another set, and is often used to write graceful single-line commands that are powerful.

TR (option) (parameter)


-C or--complerment: Supersedes all characters that are not part of the first character set;

-D or--delete: Deletes all characters belonging to the first character set;

-S or--squeeze-repeats: the consecutive repeating character is represented by a single character;

- t or--truncate-set1: Deletes the first character set more Change characters that are more than the second character set.


Converts an input character from uppercase to lowercase:

The echo "HELLO W[object Object" character set complements all characters from the input text that are not in the complement: the [Object object] complement contains the number 0~9, the space, and the newline character \ n, so it has not been deleted and all other characters have been deleted. Adding numbers using TR: [Object Object]
Delete the empty line of the specified file: Tr-s ' \ n '-s removes the duplicate element, leaving only the unique. The character classes that TR can use: [: Alnum:]: Letters and Numbers [: Alpha:]: Letters [: Cntrl:]: Control (nonprinting) characters [:d igit:]: Number [: Graph:]: Graphic characters [: lower:]: lowercase Letters [:p rint: ]: printable character [:p unct:]: Punctuation [: Space:]: blank character [: Upper:]: Uppercase [: xdigit:]: hexadecimal character tr ' [: Lower:] ' [: Upper:] '

A detailed description of TR usage in Linux

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.