Skip to content

Latest commit

 

History

History
39 lines (23 loc) · 914 Bytes

File metadata and controls

39 lines (23 loc) · 914 Bytes

Using sed

Bash allows you to perform pattern replacement using variable expansion with sed(stream editor).

To replace a value means, we're searching for this value and replacing it with another one.

Replace characters

To replace all e's with a upercae X:

echo "replace all es in this line" | sed 's/e/X/g'

rXplacX all Xs in this linX

Remove value

Removing is also a kind of replacement. We're searching for value and replacing it with nothing.

echo "remove all spaces of this line" | sed 's/ //g'

removeallspacesofthisline

Using special characters

In my cases, special characters are characters like: :, / and so on.

To remove the scheme of an URI including ://:

echo "https://www.example.com" | sed 's#https://##g'

www.example.com

Here I use # instead of / for sed to avoid conflicts with the searching value: https://.