Quantcast
Channel: Filter YAML file content using sed/awk - Unix & Linux Stack Exchange
Browsing all 5 articles
Browse latest View live

Answer by Rakesh Sharma for Filter YAML file content using sed/awk

You can do this using GNU sed as shown: $ sed -nEe ' /\[/!{H;$!d;} x;1!s/^\[(prod|dev)_env]\n//p ' hosts.yml

View Article



Answer by JJoao for Filter YAML file content using sed/awk

awk 'BEGIN{RS="[";FS="]\n"} $1 ~/(prod|dev)_env/ {print $2}' ex1

View Article

Answer by Philippos for Filter YAML file content using sed/awk

An sed solution: sed -nEe '/\[(prod|dev)_env]/!d;N;:loop' -e 's/.*\n//;${p;d;};N;P;/\n\[/D;bloop' hosts.yml /\[(prod|dev)_env]/!d drops all lines until [prod_env] or [dev_env] ist found N;:loop adds...

View Article

Answer by Søren Falch for Filter YAML file content using sed/awk

You could do (on a mac): tr "\n" "\t" < hosts.yml | sed $'s%\t\\[%\\\n\[%g' | grep 'prod\|dev' | sed $'s%.*\]\\\t%%g' | tr "\t" "\n" tr will get everything on one line The first sed will break line...

View Article

Filter YAML file content using sed/awk

I have a text file with the following content in it. $ cat hosts.yml [prod_env] foo.example.com bar.example.com [stage_env] foo_stage.example.com bar_stage.example.com [dev_env] foo_dev1.example.com...

View Article

Browsing all 5 articles
Browse latest View live




Latest Images