Parse xrandr output to get available resolution


up vote
1
down vote
favorite
I have xrandr output as follows
HDMI1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 480mm x 270mm
1920x1080 60.00*+ 50.00 59.94
1920x1080i 60.00 50.00 59.94
1680x1050 59.88
1400x1050 59.95
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.90
1280x800 59.91
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 60.00
800x600 75.00 60.32
720x576 50.00
720x480 60.00 59.94
640x480 75.00 60.00 59.94
720x400 70.08
HDMI2 disconnected (normal left inverted right x axis y axis)
VGA1 connected 1600x900+1920+0 (normal left inverted right x axis y axis) 440mm x 250mm
1600x900 60.00*+
1440x900 59.89
1280x800 59.81
1152x864 75.00
1280x720 60.00
1024x768 75.03 60.00
832x624 74.55
800x600 75.00 60.32 56.25
640x480 75.00 59.94
720x400 70.08
How can compose a bash script to get the available resolutions from xrandr result above.
for examplethe-script HDMI1
will output only
HDMI1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 480mm x 270mm
1920x1080 60.00*+ 50.00 59.94
1920x1080i 60.00 50.00 59.94
1680x1050 59.88
1400x1050 59.95
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.90
1280x800 59.91
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 60.00
800x600 75.00 60.32
720x576 50.00
720x480 60.00 59.94
640x480 75.00 60.00 59.94
720x400 70.08
I have tried
xrandr | awk '/HDMI1.*?/,/.*connected [0-9].*/'
while the result is close to what I want, but using
xrandr | awk '/VGA1.*?/,/.*connected [0-9].*/'
does not list the resolutions under VGA1 output.
Any help appreciated, thank you.
command-line multiple-monitors display display-resolution xrandr
add a comment |Â
up vote
1
down vote
favorite
I have xrandr output as follows
HDMI1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 480mm x 270mm
1920x1080 60.00*+ 50.00 59.94
1920x1080i 60.00 50.00 59.94
1680x1050 59.88
1400x1050 59.95
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.90
1280x800 59.91
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 60.00
800x600 75.00 60.32
720x576 50.00
720x480 60.00 59.94
640x480 75.00 60.00 59.94
720x400 70.08
HDMI2 disconnected (normal left inverted right x axis y axis)
VGA1 connected 1600x900+1920+0 (normal left inverted right x axis y axis) 440mm x 250mm
1600x900 60.00*+
1440x900 59.89
1280x800 59.81
1152x864 75.00
1280x720 60.00
1024x768 75.03 60.00
832x624 74.55
800x600 75.00 60.32 56.25
640x480 75.00 59.94
720x400 70.08
How can compose a bash script to get the available resolutions from xrandr result above.
for examplethe-script HDMI1
will output only
HDMI1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 480mm x 270mm
1920x1080 60.00*+ 50.00 59.94
1920x1080i 60.00 50.00 59.94
1680x1050 59.88
1400x1050 59.95
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.90
1280x800 59.91
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 60.00
800x600 75.00 60.32
720x576 50.00
720x480 60.00 59.94
640x480 75.00 60.00 59.94
720x400 70.08
I have tried
xrandr | awk '/HDMI1.*?/,/.*connected [0-9].*/'
while the result is close to what I want, but using
xrandr | awk '/VGA1.*?/,/.*connected [0-9].*/'
does not list the resolutions under VGA1 output.
Any help appreciated, thank you.
command-line multiple-monitors display display-resolution xrandr
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have xrandr output as follows
HDMI1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 480mm x 270mm
1920x1080 60.00*+ 50.00 59.94
1920x1080i 60.00 50.00 59.94
1680x1050 59.88
1400x1050 59.95
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.90
1280x800 59.91
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 60.00
800x600 75.00 60.32
720x576 50.00
720x480 60.00 59.94
640x480 75.00 60.00 59.94
720x400 70.08
HDMI2 disconnected (normal left inverted right x axis y axis)
VGA1 connected 1600x900+1920+0 (normal left inverted right x axis y axis) 440mm x 250mm
1600x900 60.00*+
1440x900 59.89
1280x800 59.81
1152x864 75.00
1280x720 60.00
1024x768 75.03 60.00
832x624 74.55
800x600 75.00 60.32 56.25
640x480 75.00 59.94
720x400 70.08
How can compose a bash script to get the available resolutions from xrandr result above.
for examplethe-script HDMI1
will output only
HDMI1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 480mm x 270mm
1920x1080 60.00*+ 50.00 59.94
1920x1080i 60.00 50.00 59.94
1680x1050 59.88
1400x1050 59.95
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.90
1280x800 59.91
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 60.00
800x600 75.00 60.32
720x576 50.00
720x480 60.00 59.94
640x480 75.00 60.00 59.94
720x400 70.08
I have tried
xrandr | awk '/HDMI1.*?/,/.*connected [0-9].*/'
while the result is close to what I want, but using
xrandr | awk '/VGA1.*?/,/.*connected [0-9].*/'
does not list the resolutions under VGA1 output.
Any help appreciated, thank you.
command-line multiple-monitors display display-resolution xrandr
I have xrandr output as follows
HDMI1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 480mm x 270mm
1920x1080 60.00*+ 50.00 59.94
1920x1080i 60.00 50.00 59.94
1680x1050 59.88
1400x1050 59.95
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.90
1280x800 59.91
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 60.00
800x600 75.00 60.32
720x576 50.00
720x480 60.00 59.94
640x480 75.00 60.00 59.94
720x400 70.08
HDMI2 disconnected (normal left inverted right x axis y axis)
VGA1 connected 1600x900+1920+0 (normal left inverted right x axis y axis) 440mm x 250mm
1600x900 60.00*+
1440x900 59.89
1280x800 59.81
1152x864 75.00
1280x720 60.00
1024x768 75.03 60.00
832x624 74.55
800x600 75.00 60.32 56.25
640x480 75.00 59.94
720x400 70.08
How can compose a bash script to get the available resolutions from xrandr result above.
for examplethe-script HDMI1
will output only
HDMI1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 480mm x 270mm
1920x1080 60.00*+ 50.00 59.94
1920x1080i 60.00 50.00 59.94
1680x1050 59.88
1400x1050 59.95
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.90
1280x800 59.91
1152x864 75.00
1280x720 60.00 50.00 59.94
1024x768 75.03 60.00
800x600 75.00 60.32
720x576 50.00
720x480 60.00 59.94
640x480 75.00 60.00 59.94
720x400 70.08
I have tried
xrandr | awk '/HDMI1.*?/,/.*connected [0-9].*/'
while the result is close to what I want, but using
xrandr | awk '/VGA1.*?/,/.*connected [0-9].*/'
does not list the resolutions under VGA1 output.
Any help appreciated, thank you.
command-line multiple-monitors display display-resolution xrandr
edited May 15 at 14:03
muru
129k19271460
129k19271460
asked May 15 at 13:01
Lee
21029
21029
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
0
down vote
accepted
A simpler version of the awk command for the script:
xrandr |
awk -v monitor="^$MONITOR connected" '/connected/ p = 0
$0 ~ monitor p = 1
p'
Bottom to top:
p
tells awk to run the default action (printing) depending on whether it's true or false)- if the line matches the monitor and is connected we set
p
to true - for all other monitor lines we set
p
to false
add a comment |Â
up vote
2
down vote
Well, figure it out,
#!/bin/bash
#usage the-script XRANDR_OUTPUT_NAME
#e.g the-script HDMI1
MONITOR=$1;
xrandr | grep -v disconnected |
awk '
if(/^'$MONITOR' connected/)
print $0;
m="t";
else if(m == "t")
if (/^[a-zA-Z]/)
exit
else
print $0
'
Hope this will help some one.
Simpler:xrandr | awk -v monitor="^$MONITOR connected" '/disconnected/ p = 0 $0 ~ monitor p = 1 p'
â muru
May 15 at 14:02
yeah, very much simpler, can you repost it as answer, to be selected as solution. thanks.
â Lee
May 16 at 3:57
add a comment |Â
up vote
1
down vote
With GNU awk:
#!/bin/sh
xrandr --query | gawk -v monitor="$1" '
$0 ~ monitor && $0 !~ /disconnected/
do print
while (getline > -1 && $0 ~ /^[[:blank:]]/)
'
Usage:
$ ./the_script LVDS-1
LVDS-1 connected primary 1440x900+0+0 (normal left inverted right x axis y axis) 303mm x 190mm
1440x900 60.00*+ 59.89 50.00
1360x768 59.80 59.96
1152x864 60.00
1024x768 60.04 60.00
960x720 60.00
928x696 60.05
896x672 60.01
960x600 60.00
960x540 59.99
800x600 60.00 60.32 56.25
840x525 60.01 59.88
800x512 60.17
700x525 59.98
640x512 60.02
720x450 59.89
640x480 60.00 59.94
680x384 59.80 59.96
576x432 60.06
512x384 60.00
400x300 60.32 56.34
320x240 60.05
If you don't have GNU awk, you may need to replace [[:blank:]]
with [ t]
yes, another solution. thanks.
â Lee
May 16 at 3:58
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
A simpler version of the awk command for the script:
xrandr |
awk -v monitor="^$MONITOR connected" '/connected/ p = 0
$0 ~ monitor p = 1
p'
Bottom to top:
p
tells awk to run the default action (printing) depending on whether it's true or false)- if the line matches the monitor and is connected we set
p
to true - for all other monitor lines we set
p
to false
add a comment |Â
up vote
0
down vote
accepted
A simpler version of the awk command for the script:
xrandr |
awk -v monitor="^$MONITOR connected" '/connected/ p = 0
$0 ~ monitor p = 1
p'
Bottom to top:
p
tells awk to run the default action (printing) depending on whether it's true or false)- if the line matches the monitor and is connected we set
p
to true - for all other monitor lines we set
p
to false
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
A simpler version of the awk command for the script:
xrandr |
awk -v monitor="^$MONITOR connected" '/connected/ p = 0
$0 ~ monitor p = 1
p'
Bottom to top:
p
tells awk to run the default action (printing) depending on whether it's true or false)- if the line matches the monitor and is connected we set
p
to true - for all other monitor lines we set
p
to false
A simpler version of the awk command for the script:
xrandr |
awk -v monitor="^$MONITOR connected" '/connected/ p = 0
$0 ~ monitor p = 1
p'
Bottom to top:
p
tells awk to run the default action (printing) depending on whether it's true or false)- if the line matches the monitor and is connected we set
p
to true - for all other monitor lines we set
p
to false
answered May 16 at 6:49
muru
129k19271460
129k19271460
add a comment |Â
add a comment |Â
up vote
2
down vote
Well, figure it out,
#!/bin/bash
#usage the-script XRANDR_OUTPUT_NAME
#e.g the-script HDMI1
MONITOR=$1;
xrandr | grep -v disconnected |
awk '
if(/^'$MONITOR' connected/)
print $0;
m="t";
else if(m == "t")
if (/^[a-zA-Z]/)
exit
else
print $0
'
Hope this will help some one.
Simpler:xrandr | awk -v monitor="^$MONITOR connected" '/disconnected/ p = 0 $0 ~ monitor p = 1 p'
â muru
May 15 at 14:02
yeah, very much simpler, can you repost it as answer, to be selected as solution. thanks.
â Lee
May 16 at 3:57
add a comment |Â
up vote
2
down vote
Well, figure it out,
#!/bin/bash
#usage the-script XRANDR_OUTPUT_NAME
#e.g the-script HDMI1
MONITOR=$1;
xrandr | grep -v disconnected |
awk '
if(/^'$MONITOR' connected/)
print $0;
m="t";
else if(m == "t")
if (/^[a-zA-Z]/)
exit
else
print $0
'
Hope this will help some one.
Simpler:xrandr | awk -v monitor="^$MONITOR connected" '/disconnected/ p = 0 $0 ~ monitor p = 1 p'
â muru
May 15 at 14:02
yeah, very much simpler, can you repost it as answer, to be selected as solution. thanks.
â Lee
May 16 at 3:57
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Well, figure it out,
#!/bin/bash
#usage the-script XRANDR_OUTPUT_NAME
#e.g the-script HDMI1
MONITOR=$1;
xrandr | grep -v disconnected |
awk '
if(/^'$MONITOR' connected/)
print $0;
m="t";
else if(m == "t")
if (/^[a-zA-Z]/)
exit
else
print $0
'
Hope this will help some one.
Well, figure it out,
#!/bin/bash
#usage the-script XRANDR_OUTPUT_NAME
#e.g the-script HDMI1
MONITOR=$1;
xrandr | grep -v disconnected |
awk '
if(/^'$MONITOR' connected/)
print $0;
m="t";
else if(m == "t")
if (/^[a-zA-Z]/)
exit
else
print $0
'
Hope this will help some one.
answered May 15 at 13:44
Lee
21029
21029
Simpler:xrandr | awk -v monitor="^$MONITOR connected" '/disconnected/ p = 0 $0 ~ monitor p = 1 p'
â muru
May 15 at 14:02
yeah, very much simpler, can you repost it as answer, to be selected as solution. thanks.
â Lee
May 16 at 3:57
add a comment |Â
Simpler:xrandr | awk -v monitor="^$MONITOR connected" '/disconnected/ p = 0 $0 ~ monitor p = 1 p'
â muru
May 15 at 14:02
yeah, very much simpler, can you repost it as answer, to be selected as solution. thanks.
â Lee
May 16 at 3:57
Simpler:
xrandr | awk -v monitor="^$MONITOR connected" '/disconnected/ p = 0 $0 ~ monitor p = 1 p'
â muru
May 15 at 14:02
Simpler:
xrandr | awk -v monitor="^$MONITOR connected" '/disconnected/ p = 0 $0 ~ monitor p = 1 p'
â muru
May 15 at 14:02
yeah, very much simpler, can you repost it as answer, to be selected as solution. thanks.
â Lee
May 16 at 3:57
yeah, very much simpler, can you repost it as answer, to be selected as solution. thanks.
â Lee
May 16 at 3:57
add a comment |Â
up vote
1
down vote
With GNU awk:
#!/bin/sh
xrandr --query | gawk -v monitor="$1" '
$0 ~ monitor && $0 !~ /disconnected/
do print
while (getline > -1 && $0 ~ /^[[:blank:]]/)
'
Usage:
$ ./the_script LVDS-1
LVDS-1 connected primary 1440x900+0+0 (normal left inverted right x axis y axis) 303mm x 190mm
1440x900 60.00*+ 59.89 50.00
1360x768 59.80 59.96
1152x864 60.00
1024x768 60.04 60.00
960x720 60.00
928x696 60.05
896x672 60.01
960x600 60.00
960x540 59.99
800x600 60.00 60.32 56.25
840x525 60.01 59.88
800x512 60.17
700x525 59.98
640x512 60.02
720x450 59.89
640x480 60.00 59.94
680x384 59.80 59.96
576x432 60.06
512x384 60.00
400x300 60.32 56.34
320x240 60.05
If you don't have GNU awk, you may need to replace [[:blank:]]
with [ t]
yes, another solution. thanks.
â Lee
May 16 at 3:58
add a comment |Â
up vote
1
down vote
With GNU awk:
#!/bin/sh
xrandr --query | gawk -v monitor="$1" '
$0 ~ monitor && $0 !~ /disconnected/
do print
while (getline > -1 && $0 ~ /^[[:blank:]]/)
'
Usage:
$ ./the_script LVDS-1
LVDS-1 connected primary 1440x900+0+0 (normal left inverted right x axis y axis) 303mm x 190mm
1440x900 60.00*+ 59.89 50.00
1360x768 59.80 59.96
1152x864 60.00
1024x768 60.04 60.00
960x720 60.00
928x696 60.05
896x672 60.01
960x600 60.00
960x540 59.99
800x600 60.00 60.32 56.25
840x525 60.01 59.88
800x512 60.17
700x525 59.98
640x512 60.02
720x450 59.89
640x480 60.00 59.94
680x384 59.80 59.96
576x432 60.06
512x384 60.00
400x300 60.32 56.34
320x240 60.05
If you don't have GNU awk, you may need to replace [[:blank:]]
with [ t]
yes, another solution. thanks.
â Lee
May 16 at 3:58
add a comment |Â
up vote
1
down vote
up vote
1
down vote
With GNU awk:
#!/bin/sh
xrandr --query | gawk -v monitor="$1" '
$0 ~ monitor && $0 !~ /disconnected/
do print
while (getline > -1 && $0 ~ /^[[:blank:]]/)
'
Usage:
$ ./the_script LVDS-1
LVDS-1 connected primary 1440x900+0+0 (normal left inverted right x axis y axis) 303mm x 190mm
1440x900 60.00*+ 59.89 50.00
1360x768 59.80 59.96
1152x864 60.00
1024x768 60.04 60.00
960x720 60.00
928x696 60.05
896x672 60.01
960x600 60.00
960x540 59.99
800x600 60.00 60.32 56.25
840x525 60.01 59.88
800x512 60.17
700x525 59.98
640x512 60.02
720x450 59.89
640x480 60.00 59.94
680x384 59.80 59.96
576x432 60.06
512x384 60.00
400x300 60.32 56.34
320x240 60.05
If you don't have GNU awk, you may need to replace [[:blank:]]
with [ t]
With GNU awk:
#!/bin/sh
xrandr --query | gawk -v monitor="$1" '
$0 ~ monitor && $0 !~ /disconnected/
do print
while (getline > -1 && $0 ~ /^[[:blank:]]/)
'
Usage:
$ ./the_script LVDS-1
LVDS-1 connected primary 1440x900+0+0 (normal left inverted right x axis y axis) 303mm x 190mm
1440x900 60.00*+ 59.89 50.00
1360x768 59.80 59.96
1152x864 60.00
1024x768 60.04 60.00
960x720 60.00
928x696 60.05
896x672 60.01
960x600 60.00
960x540 59.99
800x600 60.00 60.32 56.25
840x525 60.01 59.88
800x512 60.17
700x525 59.98
640x512 60.02
720x450 59.89
640x480 60.00 59.94
680x384 59.80 59.96
576x432 60.06
512x384 60.00
400x300 60.32 56.34
320x240 60.05
If you don't have GNU awk, you may need to replace [[:blank:]]
with [ t]
answered May 15 at 14:02
steeldriver
62.2k1196164
62.2k1196164
yes, another solution. thanks.
â Lee
May 16 at 3:58
add a comment |Â
yes, another solution. thanks.
â Lee
May 16 at 3:58
yes, another solution. thanks.
â Lee
May 16 at 3:58
yes, another solution. thanks.
â Lee
May 16 at 3:58
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036520%2fparse-xrandr-output-to-get-available-resolution%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password