Sed and awk are powerful text filtering tools in the UNIX environment.
With SED and awk, it is easy to edit local files, and it is easier to use regular expressions to filter out the output of other commands.
SED represents the stream Editor, which means that sed is a flow-oriented mechanism. All inputs provided for the SED command are sent to STDOUT after being processed by SED.
The SED command does not change the input text.
Common sed format:
I. Implementation of a single SED
Sed reads each row of data and executes an action.
The syntax is:
Sed ' script ' files
Note that the script is wrapped in inverted single quotes, and the reverse single quotation mark is the ~ key character of the same key.
Script is one or more commands in the following format:
/pattern/action
Pattern is a regular expression
ACTION:P Print the data rows being processed
d Delete the data rows being processed
S/pattern1/pattern2/replaces the first expression with the second regular formula,/pattern/s/pattern1/pattern2/the original command in this case, omitting the s/pattern1/pattern2/
Ii. execution of multiple SED commands
Execute multiple SED commands with the following command:
Sed-e ' Command1 '-e ' command2 '-e ' command3 ' files
A common example is to use SED to determine a user's user id:
ID | Sed-e s/uid=//g-e s/\ (. *//g
ID Output:
Uid=500 (David) gid=500 (David)
First command:
-e s/uid=//g means replacing uuid= with null
-e s/\ (. *//g indicates that all characters from the first parenthesis are replaced with empty
Thus, the value of the UID is obtained: 500