The sed command
stream editor for filtering and transforming text 17 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.
Examples
sed 's/old/new/' file.txtReplace first occurrence per line
sed 's/old/new/g' file.txtReplace all occurrences (global)
sed 's/old/new/i' file.txtCase-insensitive
sed 's/old/new/2' file.txtReplace 2nd occurrence only
sed -i 's/old/new/g' file.txtModify file directly
sed -i.bak 's/old/new/g' file.txtModify and create .bak backup
sed '/pattern/d' file.txtDelete lines matching pattern
sed '3d' file.txtDelete line 3
sed '2,5d' file.txtDelete lines 2-5
sed '/^#/d' file.txtDelete comment lines
sed '/^$/d' file.txtDelete empty lines
sed -n '5p' file.txtPrint line 5
sed -n '2,8p' file.txtPrint lines 2-8
sed -n '/pattern/p' file.txtPrint matching lines
sed -i 's/http:/https:/g' config.txt
sed 's/^[ \t]*//' file.txt
sudo sed -i 's/sk_live_[A-Za-z0-9]*/sk_live_REDACTED/g' FILEReplace in place (the logs belong to root)