sed + remove “#” and empty lines with one sed command

If you’re worried about starting two sed processes in a pipeline for performance reasons, you probably shouldn’t be, it’s still very efficient. But based on your comment that you want to do in-place editing, you can still do that with distinct commands (sed commands rather than invocations of sed itself). You can either use multiple … Read more

Using SED with wildcard

The asterisk (*) means “zero or more of the previous item”. If you want to match any single character use sed -i ‘s/string-./string-0/g’ file.txt If you want to match any string (i.e. any single character zero or more times) use sed -i ‘s/string-.*/string-0/g’ file.txt

find matching text and replace next line

One way: Sample file $ cat file Cygwin Unix Linux Solaris AIX Using sed, replacing the next line after the pattern ‘Unix’ with ‘hi’: $ sed ‘/Unix/{n;s/.*/hi/}’ file Cygwin Unix hi Solaris AIX For your specific question: $ sed ‘/<key>ConnectionString<\/key>/{n;s/<string>.*<\/string>/<string>NEW STRING<\/string>/}’ your_file <key>ConnectionString</key> <string>NEW STRING</string>

Grep output with multiple Colors?

You can cascade greps with different colors by specifying –color=always and using the regular expression ‘foo|$’ to pass all lines. For example: tail -f myfwlog | GREP_COLOR=’01;36′ egrep –color=always ‘ssh|$’ | GREP_COLOR=’01;31′ egrep -i –color=always ‘drop|deny|$’ If you want the entire line to be highlighted, update your regular expression accordingly: …. GREP_COLOR=’01;31′ egrep -i –color=always … Read more