Interview Prep/Shell Scripting/Text processing: grep, sed, awk, cut, sort, uniq

How do you extract a value from `key=value` or `key: value` lines?

BeginnerConceptText processing: grep, sed, awk, cut, sort, uniq
Answer
grep -oP '^PORT=\K.*' app.env                # GNU grep, \K drops the prefix
awk -F= '$1 == "PORT" {print $2}' app.env
sed -n 's/^PORT=//p' app.env
awk -F': *' '$1 == "Version" {print $2}' <(dpkg -s nginx)

Anchor the key (^PORT=) so EXPORT= or SUPPORT_PORT= does not match. For real YAML, JSON or INI use yq, jq or crudini.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Text processing: grep, sed, awk, cut, sort, uniq