awk's usage
awk -F "spearator" '[BEGIN {}] [{}] [END {}]' file1 file2 *.txt
example
#---- Sperator -----
00. awk '{print $1}' info.txt
01. awk -F ";" '{print $0}' info.txt
02. awk -F "[,/t]" '{print $2, $3}' info.txt
03. awk -F "[,/t]" '{if( $1 > 100) print $2, $3;}' info.txt
#---- BEGIN and END -----
04. awk -F ",/t" 'BEGIN {num = 0;} {num++;} END { printf "total=%s/n", $num }' info.txt
05. awk -F ",/t" 'BEGIN {num = 0;} {print num++;} ' info.txt
#---- Regular Expressions -----
05. awk '/abc/ { print $1, $3} *.txt
06. awk '/abc/ { printf "find %s/n", $0}
/123/ { printf "find %s/n", $1}' *.txt
07. awk '/abc/ || /123/ { print $1, $3} *.txt
08. awk '/abc/ && /123/ { print $1, $3} *.txt
09. awk -F "[,;]" '/abc/ {print hello,$0} ; /123/ {print world,$0}' xxx.txt
10. awk '{ if ($1 ~ /Jack/) print $0 }' # ~ -> $1 match "Jack"
11. awk '{ if ($1 !~ /Jack/) print $0 }' # !~ -> $1 not match "Jack"
#---- Build Variable -----
NF: the last field in a record
RS: character can be used for the record separator
NR: the total number of input records read so far from all data files
FNR: the number of records that have been read so far from the current input file
awk's usage
awk -F "spearator" '[BEGIN {}] [{}] [END {}]' file1 file2 *.txt
example
#---- Sperator -----
00. awk '{print $1}' info.txt
01. awk -F ";" '{print $0}' info.txt
02. awk -F "[,/t]" '{print $2, $3}' info.txt
03. awk -F "[,/t]" '{if( $1 > 100) print $2, $3;}' info.txt
#---- BEGIN and END -----
04. awk -F ",/t" 'BEGIN {num = 0;} {num++;} END { printf "total=%s/n", $num }' info.txt
05. awk -F ",/t" 'BEGIN {num = 0;} {print num++;} ' info.txt
#---- Regular Expressions -----
05. awk '/abc/ { print $1, $3} *.txt
06. awk '/abc/ { printf "find %s/n", $0}
/123/ { printf "find %s/n", $1}' *.txt
07. awk '/abc/ || /123/ { print $1, $3} *.txt
08. awk '/abc/ && /123/ { print $1, $3} *.txt
09. awk -F "[,;]" '/abc/ {print hello,$0} ; /123/ {print world,$0}' xxx.txt
10. awk '{ if ($1 ~ /Jack/) print $0 }' # ~ -> $1 match "Jack"
11. awk '{ if ($1 !~ /Jack/) print $0 }' # !~ -> $1 not match "Jack"
#条件判断
awk '{if( $4 == "false") print FILENAME,$1;}' data.txt
#搜索多个目录
awk '{if( $4 == "false") print FILENAME,$1;}' /data/*/*.csv /data2/*/*.csv
#---- Build Variable -----
NF: the last field in a record
RS: character can be used for the record separator
NR: the total number of input records read so far from all data files
FNR: the number of records that have been read so far from the current input file
FILENAME:当前文件名