sed正则表达式来查找显示器分辨率 [英] sed regex to find monitor resolution

查看:231
本文介绍了sed正则表达式来查找显示器分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 xrandr | grep'*'我想找到我们网络上所有监视器的x分辨率。这是为了帮助在其他脚本中自动放置xterm。



我们的一些系统运行的是redhat 6.4和其他的redhat 5.8,而xrandr的结果因红帽而异版本



对于redhat 6.4 xrandr | grep'*' returns



1680x1050 60.0 * +



和redhat 5.8



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



我试过 xrandr | grep'*'| sed's / \ s + \(\d\ {4 \} \)\s * x \s * \d + / \ 1 /'但这个返回与5.8和6.4中突出显示的相同的字符串。在这两种情况下,所需的输出都是1680

任何提示?

解决方案

试试这一行:

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

示例:

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

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

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


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.

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

For redhat 6.4 xrandr | grep '*' returns

1680x1050 60.0*+

and for redhat 5.8

*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

Any hints?

解决方案

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.

another way you could try, using xdpyinfo

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

这篇关于sed正则表达式来查找显示器分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆