⚡ 100% In-Browser & Private: Your data never leaves your computer. Powered by Cloudflare Edge CDN.
ProWebTools PRO
Developer & SEO Utilities
20+ Commands

Sed & Awk Text Processing Commands Matrix

The complete Sed and Awk command cheat sheet for Linux sysadmins and DevOps: regex replacement (s///), in-place editing (-i), line deletions, Awk column printing ($1, $NF), delimiter parsing (-F), and frequency counts with 1-click copy.

Sed Stream Editing (7 commands)

Sed Stream Editing
sed 's/foo/bar/' file.txt

Replaces the first occurrence of "foo" with "bar" on each line and prints to stdout.

PRO TIP Original file is untouched; output streams directly to standard out.
Sed Stream Editing
sed 's/foo/bar/g' file.txt

Replaces all occurrences (global flag /g) of "foo" with "bar" on every line.

PRO TIP Add /I flag (e.g. s/foo/bar/gI) for case-insensitive regular expression matching.
Sed Stream Editing
sed -i.bak 's/localhost/127.0.0.1/g' config.env

Edits the file in-place (-i) while safely creating an unedited backup copy (config.env.bak).

PRO TIP On macOS/BSD, sed -i requires a mandatory empty string argument: sed -i "" "s/.../..." file.
Sed Stream Editing
sed -E 's/([0-9]{4})-([0-9]{2})-([0-9]{2})/\3.\2.\1/g' dates.txt

Uses extended regular expressions (-E) to capture date groups and reformats YYYY-MM-DD to DD.MM.YYYY.

PRO TIP Use -E to avoid escaping capturing parentheses and curly braces.
Sed Stream Editing
sed '/^#/d; /^$/d' nginx.conf

Deletes (/d) all comment lines starting with # and all empty lines, streaming clean configuration.

PRO TIP Pipe to wc -l to instantly count active non-comment configuration directives.
Sed Stream Editing
sed -n '10,25p' access.log

Suppresses automatic line printing (-n) and prints exclusively line numbers 10 through 25.

PRO TIP Much faster and more memory-efficient than head and tail combinations on gigabyte-sized log files.
Sed Stream Editing
sed -n '/ERROR/,/END_TRACE/p' app.log

Prints all lines between the opening pattern /ERROR/ and closing pattern /END_TRACE/ inclusive.

PRO TIP Indispensable for isolating multiline stack traces in distributed server logs.

Awk Field Processing (8 commands)

Awk Field Processing
awk '{print $1, $NF}' access.log

Extracts and prints the first field ($1, usually IP) and the last field ($NF) of each line.

PRO TIP $NF dynamically resolves to the number of fields, guaranteeing extraction of the final column.
Awk Field Processing
awk -F':' '{print $1, $3, $6}' /etc/passwd

Sets custom field delimiter to colon (-F':') and prints username ($1), UID ($3), and home directory ($6).

PRO TIP Use -F',' for CSV files or -F'\t' for tab-separated data files.
Awk Field Processing
awk -F',' '$3 > 500 {print $1, $3}' billing.csv

Evaluates numeric condition on column 3 and outputs rows where invoice amount exceeds $500.

PRO TIP Awk automatically casts fields to floating-point numbers when relational operators (<, >, ==) are used.
Awk Field Processing
awk '{sum += $5} END {print "Total:", sum, "bytes"}' access.log

Accumulates byte sizes from column 5 into variable sum and prints the grand total at EOF (END block).

PRO TIP Initialize variables in a BEGIN { ... } block if formatting custom header tables.
Awk Field Processing
awk '{count[$1]++} END {for (ip in count) print count[ip], ip}' access.log | sort -nr | head -10

Builds an associative frequency hash table of IP addresses and outputs the top 10 most frequent visitors.

PRO TIP Classic one-liner for forensic analysis of web server access traffic spikes and scraper bots.
Awk Field Processing
awk 'NF > 0' raw_data.txt

Filters out blank or whitespace-only lines (NF = Number of Fields must be greater than zero).

PRO TIP Cleaner and more robust than grep -v "^$" because it handles lines with spaces and tabs.
Awk Field Processing
awk 'NR==FNR {a[$1]=$2; next} $1 in a {print $1, a[$1], $2}' file1.txt file2.txt

Performs an in-memory inner join between two tabular files based on the primary key in column 1.

PRO TIP NR is the total record count; FNR is the per-file record count. NR==FNR matches lines in file1.
Awk Field Processing
awk '{printf "%-20s | %10.2f MB\n", $1, $2 / 1024 / 1024}' disk.txt

Formats structured tabular output using C-style printf with left-aligned strings and fixed decimal floats.

PRO TIP Ensures terminal reports align cleanly into columns without installing third-party table CLIs.