Last active
April 13, 2022 09:57
-
-
Save peterkir/34812d09d5942b733205e43dd5bfc896 to your computer and use it in GitHub Desktop.
bash sed examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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