Basic
Replace
sed -i 's/before/after/' file
Execute multiple commands in the same line
Value
sed -i 's/'$value'/after/' file
Save
sed -i 's/abc\(def\)/ghi/' file # ghidef
sed -i 's/abc\(def\)/\1/' file # defdef
sed -i 's/abc.*/[&]/' file # [abc.*]
Delete
sed -i '1,$d' file # remove 1-end line
sed -i 's/abc//' file # delete all abc
Note
- Special matching characters need to be escaped
Question
- Cannot execute when the variable contains special characters
Refrence
Basic
Replace
sed -i 's/before/after/' fileExecute multiple commands in the same line
Value
Save
Delete
Note
Question
Refrence