Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use sed and awk commands in linux

Shulou Source: shulou.com Published: 2022-06-01 22:41:37 11月02日 Update

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.

Tags: File command statement content line character meaning number data more regular knowledge article expression this is query practical two parameters that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux Shulou Technology Redmi OPPO Reno