Run awk script from file

Load awk program from an external script file

awk -f transform.awk input.txt

tool
awk15 commands
tags
awklinux

More awk commands

  • awk '{gsub(/foo/, "bar"); print}' input.txt > tmp && mv tmp input.txt

    Global substitution and write back to same file

  • gawk -v FPAT='([^,]+)|("[^"]+")' '{print $2}' data.csv

    Parse quoted CSV fields correctly with FPAT in gawk

  • awk 'BEGIN{print "Start"} {lines++} END{print lines" lines processed"}' file.txt

    Run code before and after processing all lines

  • awk 'NR==FNR{a[$1]=$2; next} $1 in a {print $0, a[$1]}' lookup.txt data.txt

    Left-join data.txt with lookup.txt on first field

  • awk '{print $3}' file.txt

    Print the 3rd whitespace-delimited field

all 15 awk commands