More in Text Processing
Extract matches with a regular expression
Text Processing
grep -o prints only the matching part, which turns grep into a crude extractor.
Sort and deduplicate lines by a field
Text Processing
Sorts on the second column and keeps the first row of each group.
Replace text across a whole project
Text Processing
ripgrep finds the files, sed edits them in place. The dry run first is not optional.
A regular expression for ISO 8601 dates
Text Processing
Matches a date, optionally with a time and a zone. Deliberately strict about separators.
Rewrite a CSV column with perl
Text Processing
A one-liner that upper-cases the second field of every row, leaving the rest alone.
Sum a column with awk
Text Processing
Adds the third field of every line and prints the total, ignoring anything non-numeric.
Random picks
Parse arguments without a dependency
Python
argparse covers subcommands, types and help text, which is more than most scripts ever need.
Inspect a TLS certificate from the command line
Networking
Prints the subject, issuer and validity dates without opening a browser.
Narrow a union with a type guard
TypeScript
A predicate returning `x is T` teaches the compiler what a runtime check proved.
Table sizes, largest first
Databases
Where the disk actually went, including indexes and TOAST.
Exhaustiveness check on a switch
TypeScript
Assigning to never makes the compiler fail the build when a new union member is added and left unhandled.
Chunk an iterable into fixed-size batches
Python
itertools.batched on 3.12 and later; the islice version works everywhere and never materialises the whole input.
Find the largest files with PowerShell
Shell
The Windows counterpart to du | sort | head.
Read a large file without loading it into memory
Python
Iterating a file object yields one line at a time, which is the difference between a constant footprint and an OOM.