SED: Stream Editor for Text Manipulation/shaare/Uadn6w
-
Basic Replace Syntax:
-
sed -i 's/KENNY/LENNY/g' filename
-
Substitute all occurrences of "KENNY" with "LENNY"
-
-
Delete Line Containing String:
sed -i '/SEINFELD/d' filename
-
Delete Empty Lines:
sed -i '/^$/d' filename
-
Delete First Line:
sed '1d' filename
-
sed '1,2d' filename
→ delete the first two lines -
sed 's/\t/ /g' filename
→ replace tabs with spaces -
sed -n '12,18p' filename
→ print only lines 12 to 18 -
sed '12,18d' filename
→ delete lines 12 to 18 -
sed G filename
→ insert an empty line after every line -
sed '8!s/seinfeld/S1/' filename
→ replace "seinfeld" with "S1" on every line except line 8