sed regex查找监视器分辨率

时间:2021-11-15 16:50:47

Using xrandr | grep '*' I would like to find the x resolution of all monitors on our network. This is to assist in the automatic placement of xterms in other scripts.

使用xrandr | grep '*,我希望找到我们网络上所有监视器的x分辨率。这有助于在其他脚本中自动放置xterms。

Some of our systems are running redhat 6.4 and others redhat 5.8 and the results of xrandr differs depending on redhat version

我们的一些系统运行的是redhat 6.4和redhat 5.8, xrandr的结果取决于redhat版本

For redhat 6.4 xrandr | grep '*' returns

对于redhat 6.4 xrandr | grep '*'返回

1680x1050 60.0*+

1680 x1050 60.0 * +

and for redhat 5.8

对于redhat 5.8

*0 1680 x 1050 ( 474mm x 303mm ) *50

*0 1680 x 1050 (474mm x 303mm) *50

I have tried xrandr | grep '*' | sed 's/\s+\(\d\{4\}\)\s*x\s*\d+/\1/' but this returns the same string as highlighted above for 5.8 and 6.4. The desired output is 1680 in both cases

我已经尝试过xrandr | grep '* | sed 's/\s+\(\d {4\)\s*x\s* s*\ s*\d+/\1/' ',但它返回的字符串与上面强调的5.8和6.4相同。在这两种情况下,期望输出是1680

Any hints?

有提示吗?

1 个解决方案

#1


1  

try this line:

试试这条线:

xrandr|grep -Po '\d+(?=\s*x.*\*.*)'

example:

例子:

kent$ echo '1680x1050 60.0*+
*0 8888 x 1050 ( 474mm x 303mm ) *50
without star'|grep -Po '\d+(?=\s*x.*\*.*)'
1680
8888

In the example above I changed one X to 8888 and add oneline without * to show that it works for those cases.

在上面的示例中,我将一个X更改为8888,并添加不带*的oneline,以显示它适用于这些情况。

another way you could try, using xdpyinfo

另一种方法可以尝试,使用xdpyinfo

 xdpyinfo| grep dimens|grep -oP '(?<=\s)\d+'

#1


1  

try this line:

试试这条线:

xrandr|grep -Po '\d+(?=\s*x.*\*.*)'

example:

例子:

kent$ echo '1680x1050 60.0*+
*0 8888 x 1050 ( 474mm x 303mm ) *50
without star'|grep -Po '\d+(?=\s*x.*\*.*)'
1680
8888

In the example above I changed one X to 8888 and add oneline without * to show that it works for those cases.

在上面的示例中,我将一个X更改为8888,并添加不带*的oneline,以显示它适用于这些情况。

another way you could try, using xdpyinfo

另一种方法可以尝试,使用xdpyinfo

 xdpyinfo| grep dimens|grep -oP '(?<=\s)\d+'