How to remove every other line with sed?

GNU sed has a suitable addressing mode: sed -n ‘1~2!p’ file which means, starting from line 1, and with step 2, print all other lines. Equivalently, you can drop the -n, and delete matching lines: sed ‘1~2d’ It can also be done using awk: awk ‘NR%2==0’ file (Whenever line number is a multiple of 2, … 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

Using different delimiters in sed commands and range addresses

You can use an alternative regex delimiter as a search pattern by backslashing it: sed ‘\,some/path,d’ And just use it as is for the s command: sed ‘s,some/path,other/path,’ You probably want to protect other metacharacters, though; this is a good place to use Perl and quotemeta, or equivalents in other scripting languages. From man sed: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)