The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →sed 's/port/listen_port/g' app.yml replaces every occurrence of the letters port on each line, including occurrences inside longer names and paths. To target a standalone word with GNU sed, add word boundaries; before changing a file in place, preview the transformed output and inspect a diff.
Why the command changed four lines
In s/port/listen_port/g, port is an unanchored regular-expression pattern. It can match those four letters wherever they occur, not just when they form a separate word. The trailing g asks sed to replace every match on each line.
As an Amazon Associate I earn from qualifying purchases.
Anguishe’s October 1, 2026 DEV Community article describes a YAML example with port: 8080, support_email: [email protected], transport: tcp, and report_dir: /var/reports. The article reports that sed -i 's/port/listen_port/g' app.yml changed all four lines. That is an author-reported example: the pattern also matches the port substring in each longer name or path.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11This is not sed guessing incorrectly; it follows the pattern it was given. A successful exit status indicates that the command ran, not that the resulting text matches your intention.
#1 Best Overall
How to match standalone port with GNU sed
GNU sed 4.10 supports b for a word boundary. Use it on both sides of the pattern:
sed 's/bportb/listen_port/g' app.yml
GNU sed defines word characters as letters, digits, and underscores. That means port in db_port is not a standalone word under this rule, because the underscore counts as a word character. The pattern will match port when it is separated from neighboring characters by a boundary, such as whitespace or punctuation.
b is GNU-specific rather than portable POSIX sed syntax. Boundary and in-place editing options vary among sed implementations, so check the manual for the sed actually used—especially in scripts that must run on multiple platforms.
Preview the result before writing it
A safer workflow is to transform standard output first, compare it with the original, and only then decide whether to edit the file. Anguishe’s article gives this preview command:
sed 's/bportb/listen_port/g' app.yml | diff app.yml -
Here, diff compares the original file with the transformed output from standard input (the - argument). Review the displayed changes and confirm that only the intended value changed before running an in-place edit. A diff exit status of 1 ordinarily means differences were found; it is not by itself proof that sed failed.
For the original unbounded pattern, the same preview technique would expose the unwanted matches before they reached disk. Treat preview-and-review as a separate safety step, not as a replacement for writing a precise pattern.
Rank #4
Choose the edit method that matches the data
| Approach | Match scope | Portability and review |
|---|---|---|
s/port/listen_port/g |
Every occurrence of the substring port on each line, including inside larger identifiers or paths. |
Simple, but too broad for a standalone-word change. Preview and inspect a diff before any in-place edit. |
s/bportb/listen_port/g |
Standalone port according to GNU sed’s word-character rules; underscores count as word characters. |
b is GNU-specific. Check the target implementation and preview the output. |
| A format-aware parser | Can target a YAML or JSON field by its structure rather than matching text wherever it appears. | Prefer this when the intended change depends on which key or value is being edited. Use a YAML parser for YAML or a JSON-aware tool such as jq for JSON. |
Plain sed processes input line by line, which makes it useful for many text substitutions. GNU sed can also put multiple lines into its pattern space with commands such as N, so it is not accurate to say sed can never work across newlines. But when an edit depends on YAML or JSON structure, a parser that understands that format is generally the clearer choice.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Check the replacement text as well as the pattern
sed gives some characters special meaning on the replacement side too. An unescaped & inserts the entire text matched by the pattern; to put a literal ampersand in the replacement, escape it as &. This behavior is specified by both the GNU sed manual and POSIX. If a pattern or replacement contains many slashes, sed also allows a different single-character delimiter, which can make the expression easier to read.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

