Delete lines using line numbers

Lang: bash
# delete single line
sed -i '' -e '27d' ~/.ssh/known_hosts
# on FreeBSD / OS X
sed -i '' -e '27d' ~/.ssh/known_hosts
Lang: bash
# Print Odd Numbered Lines,
sed -n 'p;n'
# Print Even Numbered Lines,
sed -n 'n;p'

Search and replace text

Lang: bash
# preview output
$ git ls-files -- themes/terminal/assets/ | \
  xargs sed -En "s/(theme)-(dark|light)/\1--\2/p"
bodyClassList.add("theme--dark");
bodyClassList.add("theme--light");
bodyClassList.add("theme--dark");

# search and replce in place
git ls-files -- themes/terminal/assets/ | \
xargs sed -Ei "s/(theme)-(dark|light)/\1--\2/"

Extract numbers at the end of line

Example: extract shellcheck error codes

Lang: bash
$ git grep -n "shellcheck" dot-bashrc | \
  sed -nE "s/.*=(SC)?([0-9]+)$/\1\2/p" | sort -u
1087
2034
2154
2296
SC1090
SC1091
SC2016
SC2034
SC2120