I have a regular expression that I'm using to try to detect screen resolution as follows
xrandr | grep -P '(.*\d+x\d+)* | awk {'print$3'}
which when I use in my script gives me something like this
Output
1920x1200+0+0
1920x1200+1920+0
primary
1920x1200+1920+1200
I tried using lookahead, but I'm not using it correctly I guess because I'm getting the same match.
Code
xrandr | grep -P '(.*\d+x\d+)*^(?![\+]+\d\+\d) | awk {'print$3'}
Can someone explain how lookahead works with special characters so I can fix this? I want to only return the screen resolution in the form below or some variation. What I'm trying to do is distinguish between dual and 4 monitor displays.
xrandr | grep -P '(.*\d+x\d+)*^(?![\+]+\d\+\d) | awk {'print$3'} | tr -d '\\n'
Expectation
1920x12001920x1200primary1920x1200
or this
1920x1200
1920x1200
primary
1920x1200
Bonus points if it can return just the screen resolution.
1920x1200
1920x1200
1920x1200
1920x1200
xrandr output
Mon0 connected 1920x1200+0+0 0mm x 0 mm
1920x1200_c 59.95*
Mon0 connected 1920x1200+0+0 0mm x 0 mm
1920x1200_c 59.95*
Mon0 connected primary 1920x1200+0+1200 0mm x 0 mm
1920x1200_c 59.95*
Mon0 connected 1029x1200+1920+1200 0mm x 0 mm
1920x1200_c 59.95*
xrandr | grep -P '.*\d+x\d+(?=\+\d+\+\d+)'
– Jungly