how to match one word or another, within a single line, with sed

Aquarius Power picture Aquarius Power · Nov 11, 2013 · Viewed 13.4k times · Source

For this command xwininfo -id 0x8a00004 |grep "Absolute\|Width\|Height" I have this output

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

by using a single sed command, I want it to become this:

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

My current code is this:

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

I am aware that to match words with sed, I need to use \bWordToMatch\b on the expression, but I cannot find a way to put it where ([XY]) is on my command... I am aware also that to match "one OR other" word, I need to use \|, that I cant guess either..

Answer

jkshah picture jkshah · Nov 11, 2013

Try following sed

sed -r 's/.*(X|Y|Width|Height)\s*:\s*([0-9]+)/n\1=\2/'