Basic mode
Use # to separate
Print all
- ##awk '{print $1,$3}' a.txt
Print 1st , 3 columns
- awk 'BEGIN{print "0"}{print $1}' a.txt
The first line prints 0
- awk '{print $1}END{print "0"}' a.txt
The last line prints 0
- awk '$1 == "0" {print $0}' a.txt
The row where the first column is equal to 0
- awk '$1!="0" {print $0}' a.txt
The first column is not equal to 0
The rows where the first column is less than or equal to the second column
Regular match all rows whose columns do not contain 0
- awk '$1~/(12|(34)/ ' a.txt
Regular match the first column matching 12 or 34 rows
- awk 'if($1>1 && $2< ;1) {print $1} a.txt
The first column of the row where the first column is greater than 1 and the second column is less than 1
- awk 'if($1>1 || $2<1) {print $2} a.txt
The first column is greater than 1 or the second column is less than 1 Two columns
- awk '{print NF RS NR}' a.txt
Continuously print the number of record columns, record separator, and read Number of records
- awk 'NR==FNR {print $1} NR>FNR {print $2}' a.txt b.txt
Print the first column of the first file and the second column of the second file
- awk '{$1=$1*2; print $1}' a.txt
Modify numerical value printing
##awk 'BEGIN{LAST=0} {if($1>LAST) print $1; LAST=$1}'-
Compare one by one and print the increasing sequence
awk '{total+=$1} END {print total}' a.txt Statistical column value
awk '{printf "%c", $1}' a.txt Formatted output
awk '{print match($1, "1")}' a.txt Print the position of the first 1 in the first column , no printing 0
awk '{gsub(/ab/,"cd",$1); print $0}' a.txt First column string replacement
awk '{MAP[$1]=$2} END {for(I in MAP){print I, MAP[I]} }' a. txt Dictionary storage and retrieval
The above is the detailed content of Linux Shell Programming Example Tutorial. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn