Last active
May 4, 2018 11:00
-
-
Save Lirt/c925cf225816ab28bf6aaebc43b57225 to your computer and use it in GitHub Desktop.
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
# Print lines from line which match pattern to end of file | |
pattern="" | |
sed -n "/$pattern/,$ p" file.txt | |
# Example | |
pattern="mnop" | |
str="$(echo -e "abcd\nefgh\nijkl\nmnop\nqrst\nuvw\nxyz" | sed -n "/$pattern/,$ p")" | |
echo $str | |
# Remove lines before line LINE including LINE | |
sed '1,/LINE/d' file.txt | |
# Sed append after expr | |
sed -i "/PATTERN/a APPEND_PATTERN ${d}" file.txt | |
# Sed insert before expr | |
sed -i '/EXPR/i\ | |
INSERT_THINGS' file.txt | |
# Sed delete line | |
sed -i '/PATTERN/d' file.txt | |
# Grouping and referencing groups (from pass) | |
# () + \1 \2 ... | |
sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' | |
# Change default kernel in grub | |
sed -i 's/GRUB_DEFAULT=.*/GRUB_DEFAULT=\"Advanced options for Ubuntu\>Ubuntu\, with Linux 4\.10\.0-24-generic\"/g' /etc/default/grub | |
# Double quote all words in vim | |
%s/\(\<[a-zA-Z]*\)\(:\)/"\1":/g | |
# Change to lowercase | |
%s/\(\<[a-z]*\>\)\(\":\)/\L\1\2/g | |
# Copy file with new ext by sed | |
find ./content -name '_index' | sed -e 'p;s/$/\.sk\.md/' | xargs -n2 cp | |
# Append "dn: " to every odd line | |
sed '1d; n; s/^/dn: /g' | |
sed '0~2 s/^/dn: /g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment