This is a little tip that was impossible for me to DuckDuckGo (that’s
right, I use DuckDuckGo like a verb). Like everyone who lives the daily
joy (and, frequently, deep frustration) of using the command line to
accomplish day-to-day tasks I am a fairly deft manipulator of strings.
Often, I turn to AWK to achieve powerful results quickly. There is usually no reason to
use grep with AWK. AWK lets you use Today, however, I wanted to use AWK to find the rotation of my
current display using I tried: I tried Finally, I figured it out! This is something I thought I should
document for others using the same search terms (and for myself in a
month): To get the rotation of a device from <3 AWK so darn much.Using AWK like grep
/[whatever]/ to
search for lines containing [whatever]. You can also use
/! [whatever]/ to search for the opposite of
[whatever]. After you’ve found the line you want to act
upon, you can manipulate it further using the powerful functionality of
AWK.xrandr. The name of current display
device was stored in the environment variable
$DISPLAY_DEVICE (and in this instance was
LVDS-1). I could not figure out, nor could I find the right
words to search for, how to do this.xrandr -q | awk -v device="$DISPLAY_DEVICE" '/device/ {print}'xrandr -q | awk '/'"$DISPLAY_DEVICE"'/ {print}'The Magic
awk -v device="$DISPLAY_DEVICE" '$0 ~ device {print}'xrandr if you know
the device name it’s:xrandr -q | awk -v device='LVDS-1' '$0 ~ device {gsub("([()]| primary)", ""); print $4}'
Posted