awk — Reading Files
Print entire file — dump to stdout
awk '{print}' /etc/hostname
Pipe to less with line numbers — scrollable pager
awk '{print}' /etc/services | less -N
Pipe to less — jump to line 200 on open
awk '{print}' /etc/services | less -N +200
Pipe to less — search on open (jumps to first match)
awk '{print}' /etc/services | less -N +/http
Pipe to bat — syntax-highlighted AsciiDoc
awk '!/^\/\//' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/execution.adoc | bat -l asciidoc
Pipe to bat plain style — no border, no header, just highlighted text
awk '{print}' /etc/ssh/sshd_config | bat -l ssh_config -p
Pipe to bat with line range context — highlight lines 10-30
awk '{print}' /etc/passwd | bat -l txt --highlight-line 10:30
Pipe awk filtered output to bat — strip comments then highlight
awk '!/^#/ && NF' /etc/pacman.conf | bat -l ini -p
Pipe awk range to less — read a specific section with pager
awk 'NR>=100 && NR<=200' /etc/services | less -N
awk + bat for AsciiDoc section extraction — read one section with highlighting
awk '/^== Scope/{p=1; next} /^== /{p=0} p' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/scope.adoc | bat -l asciidoc -p
Print with line numbers — cat -n replacement
awk '{printf "%4d %s\n", NR, $0}' /etc/passwd
Print line range — lines 10 through 20
awk 'NR>=10 && NR<=20' /etc/passwd
Print first 15 lines — head replacement
awk 'NR<=15' /etc/passwd
Print last 10 lines — tail replacement via circular buffer
awk '{a[NR%10]=$0} END{for(i=NR+1;i<=NR+10;i++) print a[i%10]}' /etc/passwd
Print from line 50 to end of file
awk 'NR>=50' /etc/services
Relative line numbers — restart count at 1 from a given offset
# Show lines 20-40 with relative numbering (1, 2, 3...)
awk 'NR>=20 && NR<=40 {printf "%3d %s\n", NR-19, $0}' /etc/services
Both absolute and relative line numbers
# Absolute:Relative format for a range
awk 'NR>=100 && NR<=120 {printf "%4d [%2d] %s\n", NR, NR-99, $0}' /etc/services
Page through a file — print N lines at a time (poor man’s pager)
# Lines 1-30, then 31-60, etc — change the offset
awk -v start=1 -v size=30 'NR>=start && NR<start+size' /etc/services
Read an AsciiDoc partial — strip comment lines
awk '!/^\/\//' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/execution.adoc
Read AsciiDoc — strip comments AND blank lines for dense view
awk '!/^\/\// && NF' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/scope.adoc
Read AsciiDoc — show only section headers (== lines)
awk '/^=/' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/execution.adoc
Pipe awk to cat for syntax context — numbered output
awk '{print}' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/architecture.adoc | cat -n
Pipe awk range to cat -n — numbered slice
awk 'NR>=10 && NR<=50' /etc/services | cat -n
Find a section then print N lines after it
awk '/^== Execution Plan/{found=1; n=0} found{print; if(++n>=30) exit}' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/execution.adoc
Print between two section headers — extract one section
awk '/^== Scope/{p=1; next} /^== /{p=0} p' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/scope.adoc
Count lines in multiple files — wc -l replacement with filenames
awk 'FNR==1 && NR>1{printf "%-60s %d lines\n", prev, count} {prev=FILENAME; count=FNR} END{printf "%-60s %d lines\n", prev, count}' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/*.adoc
Browse a directory of partials — show filename and first non-comment line
for f in ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/*.adoc; do
printf "%-20s %s\n" "$(basename "$f")" "$(awk '!/^\/\// && NF {print; exit}' "$f")"
done
Read file with context markers — highlight a search term
awk '{line=$0; gsub(/Phase/, ">>> Phase <<<", line); print NR, line}' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/execution.adoc
Concatenate multiple partials in reading order — like the page does
awk 'FNR==1{print "\n=== " FILENAME " ==="} !/^\/\//{print}' \
~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/summary.adoc \
~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/purpose.adoc \
~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/scope.adoc \
~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/projects/domus-literature/execution.adoc