tips
6 tips Sed
One command, setting or habit at a time about Sed: what it does, the line to copy and a caveat or two.
Text processing 6
-
Print the number of lines in a file, or the line numbers of matches, with sed.
sed -n '$=' access.log -
Upper- or lowercases a match inside the replacement part of an s command in GNU sed.
echo 'hello world' | sed 's/.*/\U&/' -
Inserts a line of text after each line that matches a pattern.
printf 'key=1\nport=80\n' | sed '/^port=/a timeout=5' -
Swaps the slash in a sed replacement for another character, so paths stay readable.
sed 's/\/mnt\/user\/appdata\/old/\/mnt\/user\/appdata\/new/' app.conf -
Prints only the lines between two line numbers, without opening an editor.
sed -n '210,218p' /etc/nginx/nginx.conf -
Edits a file in place with sed and saves the original as a backup copy.
sed -i.bak 's/old-host/new-host/g' config.txt
Nothing in this filter yet.