sed - filter and transform text - Video Man Pages @DistroTube
sed - filter and transform text - Video Man Pages  @DistroTube
Uploaded September 2025 | Updated November 2026, 4 days ago
The 'sed' command is a very powerful shell utility that is used to filter and transform text.

- Replace first instance on each line of "old" with "new" using basic regex and print to stdout:
command | sed 's/old/new/'

- Replace "old" with "new" on all lines using basic regex and print to stdout:
sed 's/old/new/g' path/to/file

- Replace case-insensitive "old" with "new" on all lines and print to stdout:
sed 's/old/new/gi' path/to/file

- Replace "old" with "OLD" on all lines using extended regex and print to stdout:
sed -E 's/(old)/\U\1/g' path/to/file
command | sed -E 's/(old)/\U\1/g'

NOTE \U convert to uppercase; \1 tells it to convert the first capture group of the sed command (which is "old").

- Replace "old" with "new" in-place in a file (writes to the file!):
sed -i 's/old/new/g' path/to/file

- Replace "old" with "new" and "first" with "second" in-place in a file (writes to the file!):
sed -i -e 's/old/new/g' -e 's/first/second/g' path/to/file

- Print the first 10 lines to stdout (similar to 'head'):
command | sed -n '10p'

NOTE The '-n' flag suppresses the printing of the entire output of the command. Without the '-n', it would print the 10 lines and then it would print the entire output from command.

- Print only lines that contain the pattern (similar to 'grep'):
sed -n '/pattern/p' path/to/file

- Delete pattern and print to stdout:
sed '/pattern/d' path/to/file

- Delete lines 1-4 of a file and create a back up file with the .bak extension:
sed -i.bak '1,4d' path/to/file

- Delete blank lines (with or without spaces/tabs) from a file and print to stdout:
sed '/^[[:space:]]*$/d' path/to/file

- Insert a new line at the beginning of file, overwriting the file in-place:
sed -i '1i\A new first line\' path/to/file

- Inserting a line before a pattern and print to stdout.
sed '/pattern/i\This is a new line' path/to/file

- Append a line after a pattern and print to stdout.
sed '/pattern/a\This is a new line' path/to/file

REFERENCED:
β–Ί gitlab.com/dwt1/vidman

WANT TO SUPPORT THE CHANNEL?
πŸ’° Patreon: patreon.com/distrotube
πŸ’³ Paypal: paypal.com/donate/?hosted_button_id=MW3ZFGS8Q9JGW
πŸ›οΈ Amazon: amzn.to/2RotFFi
πŸ‘• Teespring: teespring.com/stores/distrotube

DT ON THE WEB:
πŸ•ΈοΈ Website: http://distro.tube
πŸ“ GitLab: gitlab.com/dwt1
πŸ—¨οΈ Mastodon: fosstodon.org/@distrotube
πŸ‘« Reddit: reddit.com/r/DistroTube
πŸ“½οΈ Odysee: odysee.com/@DistroTube:2

FREE AND OPEN SOURCE SOFTWARE THAT I LIKE:
🌐 Brave Browser - brave.com
πŸ“½οΈ Open Broadcaster Software: obsproject.com
🎬 Kdenlive: kdenlive.org
🎨 GIMP: gimp.org
πŸ’» VirtualBox: virtualbox.org
πŸ—’οΈ Doom Emacs: github.com/hlissner/doom-emacs

Your support is very much appreciated. Thanks, guys!
sed - filter and transform text - Video Man Pagesmkdir -  make new directories - Video Man PagesBlanket Is A Slick Little Ambient Sound PlayerDont Let Linux Become Like This!Chat With Patrons (Dec 28, 2025)The Brilliantly Designed ProtoArc EM06 Trackball MouseHey, DT! Voice Message Edition (No Rick Rolls Plz!)Building Yet Another Pointless Linux DistroHow To Schedule Linux Jobs With CronieVaria Is A Download Manager On Steroidscal - display a calendar - Video Man PagesHas A.I. Made The Web Obsolete?
DistroTube |

'sed' - filter and transform text - Video Man Pages

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER