Skip to content

Latest commit

 

History

History
77 lines (43 loc) · 1.48 KB

linux_sed.md

File metadata and controls

77 lines (43 loc) · 1.48 KB

SED – stream editor

sed allows you to filter & transform text, it's kind of a search/replace function.

syntax:

sed -i 's/find/replace/' filename
  • -i stands for 'inplace'

Globally Replace - g

sed -i 's/find/replace/g' filename
  • last g specifies that this substitution is global.

Replace only on lines matching THE line pattern

sed '/LINE_PATTERN/s/find/replace/' filename

Find and Delete - d

sed '/LINE_PATTERN/d' filename

Multiple Commands -e

sed -e 's/find/replace/' -e 's/find2/replace2/' filename

Specify Delimiter

The character follows 's' stands for the delimiter, you can change if your text contain this delimiter.

sed 's|find|replace|' filename