Discussion on the use of sed and awk commands in linux
- 2020-06-23 02:34:45
- OfStack
This paper mainly studies the use of sed and awk commands in linux, as follows.
sed command: No redirection will actually change the content in the source file
The query
1) sed - n '/ sbin p' passwd
Means to query and print out all the lines in the passwd file containing the sbin character, two of which/represent the regular expression. -n and /p are parameters of the command and need to be used together
(2) sed - n 'xp' passwd
x is a number that prints out the x line in the passwd file
The new statement
This is added after line 1 'passwd'
Where a means add content, the number 1 means line 1, and the statement above means add content after line 1 of the passwd file
sed '1i this is the data inserted before line 1' passwd
Where i stands for insert data, the number 1 stands for line 1, and the statement above means insert text before line 1
3. sed '1c hello world' passwd
c represents substitution, and the statement means that the first line in the password file is replaced with hello world
4, sed 's/false/true/' passwd
Replaces the false character in the passwd file with the true character
Delete statements
1) sed '/ postgres d' passwd
Delete all lines in the passwd file where the regular expression matches postgres
2, sed '2d' passwd
Delete line 2 of the passwd file
conclusion
Above is the paper on linux sed command and awk command of the use of all content, hope to help you. Interested friends can continue to refer to other related topics in this site, if there is any deficiency, welcome to comment out. Thank you for your support!