DEV Community

r_tanaka
r_tanaka

Posted on

(WIP) sed personal reference

dry run

Without any option, running sed doesn't update files. So, normal mode is dry run mode.

dry run with diff

sed 's/hoge/fuga/g' sample.txt | diff sample.txt -
Enter fullscreen mode Exit fullscreen mode

dry run with beauty diff

sed 's/hoge/fuga/g' sample.txt | diff --color -u sample.txt -
Enter fullscreen mode Exit fullscreen mode

update file

-i(--in-place)

sed -i 's/hoge/fuga/g' sample.txt
Enter fullscreen mode Exit fullscreen mode

update with backup

sed -i.bak 's/hoge/fuga/g' sample.txt
Enter fullscreen mode Exit fullscreen mode

use multiple orders

sed -e 's/hoge/fuga/g' -e 's/xxxx/aaaa/g' sample.txt
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs