Insert line after match using sed

Try doing this using GNU sed: sed ‘/CLIENTSCRIPT=”foo”/a CLIENTSCRIPT2=”hello”‘ file if you want to substitute in-place, use sed -i ‘/CLIENTSCRIPT=”foo”/a CLIENTSCRIPT2=”hello”‘ file Output CLIENTSCRIPT=”foo” CLIENTSCRIPT2=”hello” CLIENTFILE=”bar” Doc see sed doc and search \a (append)

How can I parse a YAML file from a Linux shell script?

Here is a bash-only parser that leverages sed and awk to parse simple yaml files: function parse_yaml { local prefix=$2 local s=”[[:space:]]*” w='[a-zA-Z0-9_]*’ fs=$(echo @|tr @ ‘\034’) sed -ne “s|^\($s\):|\1|” \ -e “s|^\($s\)\($w\)$s:$s[\”‘]\(.*\)[\”‘]$s\$|\1$fs\2$fs\3|p” \ -e “s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p” $1 | awk -F$fs ‘{ indent = length($1)/2; vname[indent] = $2; for (i in vname) {if (i > indent) … Read more

Block Comments in a Shell Script

In bash: #!/bin/bash echo before comment : <<‘END’ bla bla blurfl END echo after comment The ‘ and ‘ around the END delimiter are important, otherwise things inside the block like for example $(command) will be parsed and executed. For an explanation, see this and this question.

How can I shuffle the lines of a text file on the Unix command line or in a shell script?

You can use shuf. On some systems at least (doesn’t appear to be in POSIX). As jleedev pointed out: sort -R might also be an option. On some systems at least; well, you get the picture. It has been pointed out that sort -R doesn’t really shuffle but instead sort items according to their hash … Read more

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