Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Babak K. Shandiz
Babak K. Shandiz

Posted on • Originally published atbabakks.github.io on

     

String Replace in Shell with sed [RE#4]

Though 99% of the time we use a text editor likevim ornano, still knowing how to do simple string manipulations via shell commands is more than necessary. The simplest use case emerges in CI/CD pipeline where you may need to replace some placeholder with a specific text (e.g., a dynamic docker image tag). 🤖

One simple tool for this purpose issed. For example, to replace “[tag]” with “abcdef” execute:

echo "docker push -t app:[tag]" | sed -e 's/[tag]/abcdef/g'
Enter fullscreen modeExit fullscreen mode

You can also usesed just likegrep and pass a file to be used as the input stream:

sed -e 's/[tag]/abcdef/g' input-file.txt
Enter fullscreen modeExit fullscreen mode

You may add more expressions by adding any number of-e expression arguments:

sed -e 's/[tag]/abcdef/g' -e 's/[image]/app/g' input-file.txt
Enter fullscreen modeExit fullscreen mode

ℹ️ To learn more useful applications ofsed have a look atthis article.


About Regular Encounters

I’ve decided to record my daily encounters with professional issues on a somewhat regular basis. Not all of them are equally important/unique/intricate, but are indeed practical, real, and of course,textually minimal.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I'm Babak - a C#, TS enthusiast. Also, I love databases, and of course SQL. Wish to learn new exciting things here.
  • Joined

More fromBabak K. Shandiz

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp