sed and awk without the man-page anxiety
sed and awk are two tiny Unix programs that move text around. sed edits files line by line (replace, delete, insert). awk reads tables and does math or filtering on columns. They are on every Mac, every Linux box, every server you SSH into. They do not need installation. They are also famously cryptic: the syntax was designed in 1977 and never updated.
This helper builds the command for you. Pick an action (substitute, delete a line, print columns, sum a column...), fill the inputs, and the right command appears on the right. Below that, a live preview runs the same logic in your browser on sample text you can edit, so you see the result before you copy and paste.
We cover the most useful subset of both tools (substitute, delete, insert / append / change lines, print ranges for sed; print columns, conditional print, count, sum, average, filter, custom program for awk), with a cookbook of 20 ready recipes: delete blank lines, squeeze spaces, sum a column, group by column and count, convert CSV to TSV, and more. Click any recipe to load it into the builder.
Caveat: the preview uses JavaScript regex, which is close to POSIX extended regex but not identical to GNU sed or BSD sed. For everyday substitutions and column work it gives the right answer. For corner cases (look-arounds, locale-aware word boundaries, complex address ranges) consult the FAQ.
How to use it
- Pick the tool at the top: sed for whole-line edits (replace, delete, print, insert) and awk for columns (print a column, sum, filter by value).
- In sed mode, choose the action (Substitute, Delete, Print only matching, Insert before line N, Append after line N, Replace line N, Print lines N to M). The right inputs appear below.
- Type your pattern and replacement for substitute, or a line number for insert / append / change. Flags (g, i, p, Nth) are chips you click on or off.
- Edit the sample input on the right to match your real data shape. The output pane updates live: you see exactly what the command does before you copy it.
- Switch on In-place edit if you want the file modified directly (`-i`). Pick GNU for Linux or BSD for macOS, the helper shows the right variant (`-i` versus `-i ""`).
- In awk mode, pick a field separator (whitespace by default, comma for CSV, semicolon, tab, or a custom character). Then pick an action: print column N, conditional print, count matches, sum, average, filter, or write a custom program.
- Open the cookbook at the bottom for 20 ready recipes (10 for sed, 10 for awk). Click any recipe to load it into the builder, edit it, and copy the final command.
- Copy the command from the right side. Paste into your terminal with your real filename instead of `file.txt`. The output pane is for verification, not for production data: run the actual command on your file when you trust the result.
When this is useful
Six real moments when sed or awk saves you minutes (or hours):
- Bulk-replacing a string across many files. You renamed a variable from `userId` to `accountId` in a project. `sed -i 's/userId/accountId/g' src/**/*.ts` does the entire codebase in one command, faster than your IDE's "find in files" and works over SSH on a server.
- Cleaning a log file before analysis. The log has blank lines, debug noise and 50 columns when you only need 3. `awk '/ERROR/ { print $1, $5, $9 }'` keeps only the error rows and only the timestamp, status and message columns. One line, no parsing library.
- Converting between CSV and TSV. A tool exports CSV, your other tool wants TSV. `awk -F',' '{$1=$1; print}' OFS='\t'` swaps separators in one go, no Python, no Excel, no temporary files.
- Pulling a date range out of a file. You need lines 1000 to 2000 of a 50,000-line log. `sed -n '1000,2000p' file.log` is instantly the answer, and works on a remote server with no extra tools.
- Summing a column from a report. The accountant sent a CSV of invoices. You want the total. `awk -F',' '{ sum += $5 } END { print sum }' invoices.csv` adds column 5 across every row in milliseconds.
- Renaming files in a folder. You have hundreds of files like `IMG_001.jpg` and want them lower-cased and dated. A loop with `sed` building each new name does the rename without a single line of code: just shell glue.