All tags
awk
Narrow down
Other tips14
- Tip
echo 'cost: 1,50 and 2,25' | awk '{n=gsub(/,/,"."); print n": "$0}'Awk gsub() replaces every match in a line or in a single fieldReplaces all matches of a pattern in the line or in one chosen column, and counts them.2 Dec 2026 - Tip
awk -F, 'NR>1 {print > ($2".csv")}' data.csvawk can split one file into several, named after a columnWrites each line to a file named after a value in that line, such as a country code.2 Dec 2026 - Tip
echo 20261201 | awk '{print substr($0,1,4)"-"substr($0,5,2)"-"substr($0,7,2)}'Awk substr() cuts a piece out of a line, like a date from a numberExtracts part of a string by start position and length, counting from 1.2 Dec 2026 - Tip
echo '2.5 3.7' | awk '{print int($1), int($2), sprintf("%.0f", $1)}'Awk int() cuts decimals off, and printf rounds half to evenShows how awk turns decimals into whole numbers, and why 2.5 can become 2.30 Nov 2026 - Tip
echo 'web1:8080,5' | awk -F'[:,]' '{print $1, $2, $3}'Awk -F '[:,]' splits a line on more than one separatorSplits fields on several different characters at once, using a regular expression as separator.30 Nov 2026 - Tip
awk 'length > 120 {print FILENAME ":" FNR ": " length}' *.pyawk 'length > 120' finds the lines that are too longLists every line above a certain length with file name and line number.30 Nov 2026 - Tip
awk 'BEGIN {RS=""} /[email protected]/' contacts.txtawk RS="" reads text in blocks separated by blank linesTreats each paragraph as one record, so you can filter whole blocks instead of single lines.30 Nov 2026 - Tip
awk -F, 'NR==FNR {name[$1]=$2; next} FNR>1 {print $1, ($2 in name ? name[$2] : "unknown"), $3}' names.csv orders.csvawk 'NR==FNR' looks up values from a second fileJoins two files on a shared column, like a small database lookup, in one awk command.30 Nov 2026 - Tip
awk NF file.txt > clean.txtawk NF removes empty lines, including the ones with only spacesDrops every line that has no visible content, also lines with just spaces or tabs.30 Nov 2026 - Tip
awk -F, 'NR>1 {s[$2]+=$3} END {for (k in s) print k, s[k]}' orders.csvawk 's[$1]+=$2' adds up a column per groupTotals a number column separately for each value in another column, like a GROUP BY.30 Nov 2026 - Tip
printf 'a b c\n' | awk -v OFS=, '{print}' # a b cAwk '$1=$1' with OFS turns spaces into commasRebuilds every line with a new field separator, for turning aligned output into CSV.30 Nov 2026 - Tip
awk -F, 'NR==1 {for (i=1; i<=NF; i++) col[$i]=i; next} {print $col["amount"]}' orders.csvawk can pick a CSV column by its header nameReads the header row once and then selects columns by name instead of by number.30 Nov 2026 - Tip
awk -F, '{s+=$2} END {print s}' costs.csvawk '{s+=$2} END {print s}' adds up a column of numbersAdds up all the numbers in one column of a file or command output.27 Nov 2026 - Tip
awk '!seen[$0]++' list.txt > unique.txtawk '!seen[$0]++' removes duplicate lines without sortingRemoves duplicate lines from a file and keeps the original order of the rest.19 Nov 2026
Network2
- Tip
echo /var/log/nginx/access.log | awk -F/ '{print $NF, $(NF-1)}'Awk '{print $NF}' prints the last column, however many there areGrabs the last field of each line, even when lines have a different number of fields.30 Nov 2026 - Tip
printf 'nginx 12.5\npostgres 300\n' | awk '{printf "%-10s %8.1f MB\n", $1, $2}'Awk printf lines up columns into a neat tableFormats output into aligned columns with fixed widths and decimals.30 Nov 2026
Security1
Storage1
Nothing matches.