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 and awk commands in linux

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article is about how to use sed command and awk command in linux. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.

1. Sed command: no redirection will not actually modify the contents of the source file

Query statement

① sed-n'/ sbin/p' passwd

Indicates that all lines with sbin characters in the passwd file are queried and printed, where two / denote regular expressions,-n and / p are parameters of the command and need to be used together

② sed-n 'xp' passwd

X is a number that prints out the data on line x in the passwd file

New statement

① sed'1a this is the content added after the first line 'passwd

Where a means to add content, 1 number indicates the number of lines, and the meaning of the above statement indicates that the content is added after the first line of the passwd file

② sed'1i this is the data inserted before the first row 'passwd

Where I represents insert data, 1 number indicates the number of rows, and the above statement means to insert text content before the first line.

3. Sed'1c hello world' passwd

C stands for substitution, and the statement means to replace the first line in the password file with hello world

4. Sed's passwd, falseAccord, true

Means to replace false characters with true characters in the passwd file

Delete statement

① sed'/ postgres/d' passwd

Delete all lines in the passwd file where regular expressions match postgres

2. Sed '2d' passwd

Delete the second line in the passwd file

The above is how to use the sed command and awk command in linux. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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