loading...
Cover image for How to parse a key-value pair list with AWK

How to parse a key-value pair list with AWK

moniquelive profile image Cyber ・1 min read

A simple example, using env as input:

$ env | grep EDITOR
EDITOR=vim
$ env | awk -F= '{a[$1]=$2} END {print(a["EDITOR"])}'
vim

It's way easier to just do echo $EDITOR though.

But sometimes it's not so easy:

$ xdotool getactivewindow getwindowgeometry --shell | awk -F= '{a[$1]=$2} END {print(a["WIDTH"])}'
1430

If you want to get the current window's width.

_

= M =

Discussion

pic
Editor guide