An example of using tr Command in Linux system
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!