sed
Take good lines, awk
command good at taking column
and
-
Format :
sed <option> <script> <file>
-
option
-e
: Execute multiple commands- The command must be separated by a semicolon
- No space between the end of the command and the semicolon
- example:
sed -e 's/brown/green; s/dog/cat' data.txt
-f
: Read commands from a file- Each command line without the semicolon
- example:
sed -f script.sed data.txt
-n
: No command output, print output command to complete
-
script
- ** s **: replacement string between the first string between the second slash slash
- example:
echo "a dog" | sed 's/dog/cat/'
- example:
- ** s **: replacement string between the first string between the second slash slash
-
file
- Not specified defaults to STDIN
-
sed does not modify file data, but to send the modified data to STDOUT
awk
-
Format :
awk <options> <program> <file>
-
option
-f
: Read commands from a file- Must
{}
beginning of the end - Each command line without the semicolon
- Must
-F
: Custom field delimiter- The default delimiter is whitespace
- example:
awk -F: '{print $1}' /etc/passwd
-
program
- You can customize variables
- You do not need a custom variable references
$
- The default variable
$0
On behalf of the entire line of text$1
1 represents the first data field$n
N represents the data fields
- You do not need a custom variable references
- Keyword
BEGIN
: Script execution defined later in the pre-processing of data- Two single quotes in the command remains the same
- example:
awk 'BEGIN {print "hello world!"} {print $0}'
END
: After the definition of the script execution in the data processing
- Semicolon between commands can execute a plurality of commands
- example:
echo "Hello World" | awk '{$2="golang"; print $0}'
- example:
- You can customize variables
-
file
- Not specified defaults to STDIN
Regular Expressions