Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example of using tr Command in Linux system

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "examples of the use of tr commands in the Linux system". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "the use of tr commands in the Linux system examples" it!

Name: tr

Location: / usr/bin/tr

Permissions: all users

Function: it can be used to delete the text in a message or to replace the text message.

Usage: tr [OPTION]. SET1 [SET2]

Options:

-d delete the string SET1 in the message

-s replaces the duplicate string

Example 1:

When tr does not have any parameter options, the default is to replace, which is consistent with the result of adding the-s parameter option.

The code is as follows:

$last | tr "[Amurz]"[Amurz]" | sed-n '1p'

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)

The code is as follows:

$last | tr-s "[Amurz]"[Amurz]" | sed-n '1meme 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 should be enclosed in quotation marks, both single and double quotation marks

For example, the 2:tr command deletes the numbers in the output of file a (this is not to modify file a)

The code is as follows:

$cat a

Pa:11:a

Sa:32:c

App:5:b

Stort:1:d

Pear:4:aa

Hello:3:f

$cat a | tr-d "[0-9]"

Pa::a

Sa::c

App::b

Stort::d

Pear::aa

Hello::f

Note: tr-d "[0-9]" file syntax is incorrect, cannot connect files, and can receive data streams through pipeline commands, etc.

At this point, I believe you have a deeper understanding of "the use of tr commands in the Linux system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report