Replace
_$: sed -i 's/old/new/g' file.txt # Replace 'old' with 'new'
_$: sed -i 's old new g' file.txt # Replace 'old' with 'new' using whitespace as separator
_$: sed -i 's/\\bold\\b/new/g' file.txt # Replace word 'old' with word 'new'
_$: sed -i 's/ /\n/g' ./file # Replace whitespace with new lines
_$: sed -i 's/\n//g' ./file # Remove newlines
_$: sed -i.bak 's/\n//g' ./file # Remove newlines saving a backup in file.bak
_$: sed -i 's <[^/] \n& g' file # Replace <pattern with \n<pattern
_$: sed -i.bak '/pattern/d' file # Delete all lines containing 'pattern'
_$: sed -i '/^[ ]*$/d' file # Delete all lines with just whitespaces
_$: sed -i 's/^[ \t]*//' file # Delete whitespaces at the beginning
_$: sed -i 's/[ \t]*$//' file # Delete whitespaces at the end
_$: sed -i 's/^[ \t]*//;s/[ \t]*$//' file # Delete whitespaces at the beginning and at the end
Replace in multiple files
_$: grep -rl 'old' ./* | xargs sed -i 's/old/new/g'
_$: grep -rli 'old' --include="*.py" ./* | xargs sed -i 's/old/new/g'
Delete
_$: sed -i '/^$/d' $1 # Delete empty lines
Read
_$: sed -n 1,250p bigfile > header # Show lines 1 to 250 (inclusive)