More in Text Processing
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.
Sort and deduplicate lines by a field
Text Processing
Sorts on the second column and keeps the first row of each group.
Extract matches with a regular expression
Text Processing
grep -o prints only the matching part, which turns grep into a crude extractor.
Pretty-print and query JSON
Text Processing
jq for the common cases: reformat, pick a path, filter an array, and reshape.
Replace text across a whole project
Text Processing
ripgrep finds the files, sed edits them in place. The dry run first is not optional.
Random picks
Run promises with a concurrency limit
JavaScript
Keeps a fixed number of jobs in flight rather than firing a thousand requests at once.
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.
Undo the last commit but keep the changes
Git
Moves HEAD back one commit and leaves everything staged, which is what you usually want after committing too early.
Retry a fetch with exponential backoff
JavaScript
Backs off on each failure and adds jitter, so a recovering service is not hit by every client at the same moment.
Find slow queries in Postgres
Databases
Ranks statements by total time spent. Needs the pg_stat_statements extension enabled.
Read a file into a string in Go
Systems
os.ReadFile replaced ioutil.ReadFile in 1.16 and is the one-liner for small files.
Find what is taking up space in an image
Containers
Prints the size each layer adds, which usually points straight at the offending RUN line.
Show which process is holding a port
Shell
Answers 'address already in use' without guessing.