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..
' [^ tab ]\+ ' (Here tab stands for a single tab character.) This matches a string of one or more characters, none of which is a space or a tab.
Regular expressions are used by several different Unix commands, including ed, sed, awk, grep, and to a more limited extent, vi.
5.1 Overview of regular expression in sed A regular expression is a pattern that is matched against a subject string from left to right. Most characters are ordinary: they stand for themselves in a pattern, and match the corresponding characters. Regular expressions in sed are specified between two slashes.
(quit) Exit sed without processing any more commands or input. (quit) This command is the same as q , but will not print the contents of pattern space. Like q , it provides the ability to return an exit code to the caller.
Try following sed
sed -r 's/.*(X|Y|Width|Height)\s*:\s*([0-9]+)/n\1=\2/'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With