Interview Prep/Real-World Interview/awk, sed, grep and jq one-liners

Using sed, insert a line after a matching line, e.g. add `include /etc/nginx/extra.conf;` after `http {`.

IntermediateHands-onawk, sed, grep and jq one-liners
Answer
sed -i '/^http {/a\    include /etc/nginx/extra.conf;' /etc/nginx/nginx.conf

Key trick → a\ appends after the match and i\ inserts before it. Run without -i first to preview. This is not idempotent, so in automation use Ansible lineinfile instead.

All Real-World Interview questions Roadmap: Interview readiness

More on awk, sed, grep and jq one-liners