Babak K. Shandiz
Babak K. Shandiz's Blog

Babak K. Shandiz's Blog

Living in the Shell #15; sed (Text Stream Editor) (Part 2)

Living in the Shell #15; sed (Text Stream Editor) (Part 2)

Babak K. Shandiz's photo
Babak K. Shandiz
ยทDec 14, 2021ยท

1 min read

sed ๐Ÿ–Š๏ธ

Edits streams by applying commonly used modifications.

Replace substring s

cat some-file.txt | sed 's/me/you/g'

Replaces all occurrences of "me" with "you".

Replace pattern s

echo "about\nabuse\namount" | sed 's/a\(\w*\?\)\w/\1/g'
bou
bus
moun

\1 refers to the first captured group.

Transform to lowercase \L

echo "HELLO THERE\nHI THERE\nGOODBYE" | sed 's/H\w*/\L&/g'
hello There
hi There
GOODBYE
  • Transforms words beginning with "H" to lowercase.
  • & is the place holder for "entire match".

Transform to uppercase \U

cat some-file.txt | sed 's/.*/\U&/g'

Transforms all letters into uppercase.

ย 
Share this