9

对于这个命令xwininfo -id 0x8a00004 |grep "Absolute\|Width\|Height",我有这个输出

Absolute upper-left X:  44
Absolute upper-left Y:  53
Width: 999
Height: 698

通过使用单个 sed 命令,我希望它变成这样:

nX=44
nY=53
nWidth=999
nHeight=698

我目前的代码是这样的:

xwininfo -id 0x8a00004 |grep "Absolute\|Width\|Height" |sed -r 's".*([XY]):[[:blank:]]*(.*)"n\1=\2"'

我知道要将单词与 sed 匹配,我需要\bWordToMatch\b在表达式上使用,但我找不到将它([XY])放在我命令的位置的方法......我也知道要匹配“一个或其他”单词,我需要使用\|,我也猜不到..

4

1 回答 1

15

尝试关注sed

sed -r 's/.*(X|Y|Width|Height)\s*:\s*([0-9]+)/n\1=\2/'
于 2013-11-11T16:48:54.950 回答