awk command
awk ' Condition 1 (Action 1) Condition 2 (Action 2) ... ' Filename
Condition (pattern)
General use of relational expressions as criteria
X>10 to determine if X is greater than 10
x>=10 greater than or equal to
x<=10 less than or equal to
Actions (Action)
-Formatted output
-Process Control Statements
Examples of awk use:
awk ' {printf $ "\ t" $ "\ n"} '
awk ' begin{printf ' Test '}{printf $ '///output the specified string before the output statement
awk ' end{printf ' Test '}{printf $ '//output the specified string after the output statement
FS Built-in variables
cat/etc/passwd | grep "/bin/bash" | awk ' begin{fs= ': "}{printf" \ T "$" \ n "} '
Begin to specify delimiters before reading data
FS built-in variable set delimiter
Relational operators
cat/etc/passwd | awk ' begin{fs= ': "}$3<300{printf" \ T "$" \ n "} '
Built-in variables commonly used by awk
ARGC number of command line arguments
ARGV Command line parameter arrangement
ENVIRON support for the use of system environment variables in queues
FileName awk browses the file name
FNR number of records to browse files
FS sets the input domain delimiter, which is equivalent to the command line-F option
NF browsing the number of fields recorded
NR number of records read
OFS output Field delimiter
ORS Output Record delimiter
RS Control record delimiter
Cut command
Cut Field Extraction command
cut[Options] File name
Options:
-F Column Number: Extract the first few columns
-D delimiter: Split columns by specified delimiter
df-h| Cut-f 1 (Unable to extract columns)
The Cut command applies a split field of comparative regularity, such as a tab
Practical command exercises to back up the created user
grep "/bin/bash"/etc/passwd | Grep-v "Root" | Cut-f 1-d ":" User.log
SED command
sed [options] ' [action] ' file name
Options:
-N: The general sed command will output all data to the screen, and if you add this option, only the rows processed by the SED command will be output to the screen
-e: Allow multiple sed command edits to input data
-I: Modify the data read file directly with the result of the SED command, instead of the screen output
Action:
-A: Append, add one or more rows after the current line
-C: Line substitution, replacing the original data row with the string following C
-I: INSERT, insert one or more rows before the current line, D: delete the specified row
-P: Print, output the specified line
-S: string substitution, replacing another string with one. The format is "line range s/old string/new string/g" (similar to the replacement format in vim)//sed ' 5s/mbb/mb/g ' user.log
printf command (Output command)
printf command (Format output command)
printf ' output type output format ' output content
Output Type:
-%ns: Output string. N is a numeric reference to output several characters
-%ni: Output integer. N is a digital reference to output several numbers
-%M.NF: The output floating-point number, M and n are numbers, which refer to the integer digits and decimal digits of the output. If the%8.2f represents a total of 8 digits, where 2 digits are decimals and 6 bits are integers.
This article is from "Linux system Operations" blog, please make sure to keep this source http://mbb97.blog.51cto.com/13129388/1964461
Shell programming Character intercept commands