Escape a string for a sed replace pattern

Warning: This does not consider newlines. For a more in-depth answer, see this SO-question instead. (Thanks, Ed Morton & Niklas Peter) Note that escaping everything is a bad idea. Sed needs many characters to be escaped to get their special meaning. For example, if you escape a digit in the replacement string, it will turn … Read more

sed edit file in place

The -i option streams the edited content into a new file and then renames it behind the scenes, anyway. Example: sed -i ‘s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g’ filename while on macOS you need: sed -i ” ‘s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g’ filename

Delete empty lines using sed

You may have spaces or tabs in your “empty” line. Use POSIX classes with sed to remove all lines containing only whitespace: sed ‘/^[[:space:]]*$/d’ A shorter version that uses ERE, for example with gnu sed: sed -r ‘/^\s*$/d’ (Note that sed does NOT support PCRE.)

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

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