Skip to content

Instantly share code, notes, and snippets.

@peterkir
Last active April 13, 2022 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterkir/34812d09d5942b733205e43dd5bfc896 to your computer and use it in GitHub Desktop.
Save peterkir/34812d09d5942b733205e43dd5bfc896 to your computer and use it in GitHub Desktop.
bash sed examples
#!/bin/bash
## composed sed usages
# soure a file into bash from java properties
# 1.sed removes emtpy lines
# 2.sed remove commented lines
# 3.sed removes windows eol
source <(cat <file> | sed --expression '/^[[:space:]]*$/d' | sed --expression '/^#.*$/d' | sed --expression 's/\r//g' )
## distinct usages
# replace all lines containing only whitespace chars
sed '/^[[:space:]]*$/d' <filename>
# remove all windows line endings
sed 's/\r//g' <filename>
# remove lines starting with #
sed --expression '/^#.*$/d'
# read from stdin
cat filename |sed --expression='s/x/y/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment