Linux Command String Conversion -- tr

Source: Internet
Author: User

Linux Command String Conversion -- tr

Name: tr

Location:/usr/bin/tr

Permission: All Users

Purpose: it can be used to delete text in a piece of information or replace text information.

Usage: tr [OPTION]... SET1 [SET2]

Option:

-D: Delete the SET1 string in the information.

-S replaces the repeated string

Example 1:

If tr does not have any Parameter options, it is replaced by default, which is consistent with the result of the-s parameter option.

$ last| tr  "[a-z]" "[A-Z]"|sed -n '1,5p'CWJY1202 PTS/0        :0               SAT JAN 10 22:14   STILL LOGGED IN   REBOOT   SYSTEM BOOT  3.2.0-24-GENERIC SAT JAN 10 21:45 - 23:48  (02:03)    CWJY1202 PTS/0        :0.0             SAT JAN 10 19:24 - DOWN   (00:00)    REBOOT   SYSTEM BOOT  3.2.0-24-GENERIC SAT JAN 10 14:17 - 19:24  (05:07)    REBOOT   SYSTEM BOOT  3.2.0-24-GENERIC FRI JAN  9 20:50 - 22:50  (01:59) 
$ last| tr -s  "[a-z]" "[A-Z]"|sed -n '1,5p'CWJY1202 PTS/0        :0               SAT JAN 10 22:14   STIL LOGED IN   REBOT   SYSTEM BOT  3.2.0-24-GENERIC SAT JAN 10 21:45 - 23:51  (02:05)    CWJY1202 PTS/0        :0.0             SAT JAN 10 19:24 - DOWN   (00:00)    REBOT   SYSTEM BOT  3.2.0-24-GENERIC SAT JAN 10 14:17 - 19:24  (05:07)    REBOT   SYSTEM BOT  3.2.0-24-GENERIC FRI JAN  9 20:50 - 22:50  (01:59)

Note: SET1 and SET2 must be enclosed by quotation marks, either single or double quotation marks.

Example 2:Tr command to delete the number in the output of file a (this is not to modify file)

$ cat apa:11:asa:32:capp:5:bstort:1:dpear:4:aahello:3:f$ cat a| tr -d "[0-9]"pa::asa::capp::bstort::dpear::aahello::f

Note: The tr-d "[0-9]" file Syntax is incorrect. Files cannot be connected. You can use pipeline commands to receive data streams.

To be continued ......

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.