Home>Article>Operation and Maintenance> How to use sed command and awk command in linux
This article mainly introduces the use of sed command and awk command in Linux. It has certain reference value. Friends in need can refer to it. I hope it can help everyone.
1. sed command: Without redirection, the content in the source file will not be actually modified
Query statement
①sed -n '/sbin/p' passwd
means to query all the lines with sbin characters in the passwd file and print them out. The two /s represent regular expressions. -n and /p are the parameters of the command. Need to be used in combination
②sed -n 'xp' passwd
x is a number, which means printing out the data of line x in the passwd file
New Add statement
①sed '1a This is the content added after the first line' passwd
where a means to add content, and the number 1 means which line it is, above The meaning of the statement means to add content after the first line of the passwd file
②sed '1i This is the data inserted before the first line' passwd
where i means insert Data, the number 1 indicates which row, the above statement means to insert text content before the first row
3, sed '1c hello world' passwd
c Indicates replacement. The statement means to replace the first line in the password file with hello world
4, sed 's/false/true/' passwd
means to replace Replace the false characters in the passwd file with true characters
Delete the statement
①sed '/postgres/d' passwd
Delete the regular expression in the passwd file Formula to match all lines of postgres
2, sed '2d' passwd
Delete the second line in the passwd file
## Summary
The above is the entire content of this article about the use of sed command and awk command in Linux. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point out. Thank you friends for supporting this site! Related recommendations:Detailed introduction to the sed command
Detailed sharing of sample code for the sed command in Linux
php cannot implement the sed command in the shell script-
The above is the detailed content of How to use sed command and awk command in linux. For more information, please follow other related articles on the PHP Chinese website!