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

How to use sed in linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to use sed in linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Detailed explanation of sed usage of linux

Sed is a good file processing tool. It is a pipeline command itself, which is mainly processed in a behavior unit. Data rows can be replaced, deleted, added, selected and other specific tasks. Let's take a look at the usage of sed.

The format of the sed command line is:

Sed [- nefri] 'command' input text

Common options:

-n ∶ uses silent mode. In the normal use of sed, all information from STDIN is generally listed on the screen. But if you add the-n argument, only the row (or action) that has been specially handled by sed will be listed.

-e ∶ edits sed actions directly in instruction line mode

-f ∶ directly writes sed actions in a file, while-f filename can perform sed actions in filename.

The action of-r ∶ sed supports the syntax of extended regular representations. (the preset is the basic formal representation syntax)

-I ∶ directly modifies the contents of the read file instead of outputting it on the screen.

Common commands:

A ∶ is added, a can be followed by strings, and these strings will appear on a new line (the current next line) ~

C ∶ instead, c can be followed by strings, these strings can replace the lines between N1 and N2!

D ∶ is deleted, because it is deleted, so there is usually no knock after d.

I ∶ insert, I can be followed by strings, and these strings will appear on a new line (the current previous line)

P ∶ printing, that is, printing a selected data. Usually p works with the parameter sed-n ~

S ∶ replacement, you can directly carry out the replacement work! Usually the action of this s can be matched with the formal representation! For example, 1Magazine 20s Universe, OldCompact newscop g is it!

Example:

Sed'2 file # delete the second line to the last line sed-n'2 P 'file # shows the second to the last line sed-n' / gene/p' file # query includes all lines where the keyword gene is located sed'1a gene' file # adds the string "gene" sed'1 line 2c gene' file # first to second line instead of genesed's genesed's Universe rna to genesed-I'/ rna/d' file # delete This is the end of the article on "how to use sed in linux" Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

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

Development

Wechat

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

12
Report