Tag: awk

awk OFS field separator with examples

Awk OFS field separator variable, output field separator. It is a pair with the Awk FS variable; awk FS separates strings as fields, and awk...

awk FS field separate with examples

awk separate string, you can use awk FS variable or awk -F option to support single delimiter and multiple delimiter regular matching....

awk merge files base on the keyword

use the awk variables NR and FNR merge files base on the keywords. awk -F' ' 'NR==FNR{a[$1]=$2;}NR!=FNR{print $0, a[$1]}' test-4.txt test-5.txt...

awk custom function and examples

Here, you need to use the awk custom function to implement the abs function. awk 'function abs(x){return (x < 0) ? -x : x;} {print...

awk loop example: awk for and while

awk for loop: awk -F"#" '{for(i=1;i<=NF;i++) { ... }' t.txt; awk for loop array: awk 'BEGIN{a["km"] = "m";a["kn"] = "n";for(i in a) {...}}'; awk while loop: awk -F"#"...

awk NR FNR difference

Linux awk command can use variables NR and FNR to process multiple files. NR : ordinal number of the current record, multiple files self-increase FNR...

AWK tutorial: awk sort uniq

In daily development, we often use awk command to cut and sort log file columns and count them. awk sort uniq count example awk column...