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

Have sed ignore non-matching lines

If you don’t want to print lines that don’t match, you can use the combination of -n option which tells sed not to print p flag which tells sed to print what is matched This gives: sed -n ‘s/…/…/p’ Additionally, you can use a preceding matching pattern /match only these lines/ to only apply the … Read more

sed: Replace part of a line

This works: sed -rne ‘s/(dbservername)\s+\w+/\1 yyy/gip’ (When you use the -r option, you don’t have to escape the parens.) Bit of explanation: -r is extended regular expressions – makes a difference to how the regex is written. -n does not print unless specified – sed prints by default otherwise, -e means what follows it is … Read more

What is the difference between sed and awk? [closed]

sed is a stream editor. It works with streams of characters on a per-line basis. It has a primitive programming language that includes goto-style loops and simple conditionals (in addition to pattern matching and address matching). There are essentially only two “variables”: pattern space and hold space. Readability of scripts can be difficult. Mathematical operations … Read more