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

The usage of the Linux basic command tr

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

Share

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

This article mainly explains "the usage of the Linux basic command tr". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the usage of the Linux basic command tr".

Tr

To delete or change a string in a file, this instruction generally requires two character sets. The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Tr [options] set1 set2

2. List of options

Option

Description

-- help

Show help documentation

-- version

Display version information

-c |-C |-- complement

Use the complement of SET1

-d |-- delete

Delete the specified content in character set 1

-s |-- squeeze-repeats

Replace the repeated content in set1 with the content that appears once

-t |-- truncate-set1

First truncate the SET1 according to the length of the SET2

Collection is specified as a string. Most people represent themselves. The explanatory sequence is:

Sequence

Description

\ NNN

Characters with octal value nnn (1 to 3 octal digits)

\\

Backslash symbol

\ a

Audible BEL

\ b

Backspace key (of the keyboard)

\ f

Change the page

\ n

New line

\ r

Return

\ t

Horizontal tab

\ v

Vertical tab

CHAR1-CHAR2

All characters from CHAR 1 to CHAR 2 are arranged in ascending order

[CHAR*]

Copy the characters in set2, which is the length of set1

[CHAR*REPEAT]

Duplicate copy

[: alnum:]

All letters and numbers

[: alpha:]

All letters

[: blank:]

All the horizontal blanks

[: cntrl:]

All control characters

[: digit:]

All the numbers.

[: graph:]

All printable characters, excluding spaces

[: lower:]

All lowercase letters

[: print:]

All printable characters, including spaces

[: punct:]

All punctuation marks

[: space:]

All horizontal and vertical spaces

[: upper:]

All capital letters

[: xdigit:]

All the hexadecimal numbers

[= CHAR=]

All characters equivalent to CHAR

If no'- dudes are given, and both SET1 and SET2 appear, translation will occur.' -t 'can only be used in translation. The Set2 is extended to the length of the SET1 by repeating the last character of the SET1 if necessary. Extra characters in Set2 will be ignored. Only [: lower:] and [: upper:] are guaranteed to unfold in ascending order; used in set2 translation, they can only be used in pairs to specify case conversion.' -s' uses SET1; compression when not translated or deleted, uses SET2 and occurs after translation or deletion.

3. Examples

1) Delete content

[root@localhost weijie] # cat 1.c

Hello world, i am david. I love linux, love code.

[root@localhost weijie] # tr-d hello < 1.c / / output the contents of 1.c to tr, then delete the characters that appear

Wrd, i am david. I v inux, v cd. / / this is not to delete a word hello, but to delete the five letters that appear

2) replace the lowercase letters in the file with uppercase

[root@localhost weijie] # tr-s Amurz Amurz < 1.c

HELO WORLD, I AM DAVID. I LOVE LINUX, LOVE CODE.

Thank you for your reading, the above is the content of "the usage of the Linux basic command tr". After the study of this article, I believe you have a deeper understanding of the usage of the Linux basic command tr, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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