Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am reading this article. There is a statement there that goes:

ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -r 25 -i :0.0 -sameq -f mpeg -ar 48000 -s wvga -y sample.mp4 

When I run the command I get an error with the section that says:

xwininfo -root | grep 'geometry' | awk '{print $2;}' 

The reason is that when you use this command on my computer it outputs:


How do I remove the last part of the screen resolution output to be 1360x768 instead of 1360x768+0+0?

share|improve this question
If you know the geometry, 1360x768, just use rather then a variable – bodhi.zazen Sep 3 '14 at 18:01
I realize this, and already did it this way successfully. But I was trying to use the experience to increase my awk knowledge as well. :) – Guest123ABC Sep 3 '14 at 18:20
OK, good luck. There are several excellent tutorials on awk on the internet. – bodhi.zazen Sep 3 '14 at 18:23
  • You can use perl to get only the resolution:

    xwininfo -root | perl -lne 's/.*geometry (\w+).*/$1/ or next; print'
  • Or even shorter with just GNU grep:

    xwininfo -root | grep -oP '(?<=geometry )\w+'

    Explanation: The lookbehind (?<=geometry ) asserts that at the current position in the string, what precedes is the characters "geometry ". If the assertion succeeds, the engine matches the resolution pattern.

    A lookbehind does not "consume" any characters on the string. This means that after the closing parenthesis, the regex engine is left standing on the very same spot in the string from which it started looking: it hasn't moved. From that position, then engine can start matching characters again.


share|improve this answer
@Guest123ABC I've updated my answer with a shorter version of the regular expression – Sylvain Pineau Sep 4 '14 at 13:17

My pure awk approach, splitting the string into fields based on spaces and plus signs:

xwininfo -root | awk -F'[+| ]' '/geometry/ {print $4}'

A similar method to Sylvain's Perl expression but with sed:

xwininfo -root | sed -nr 's/.*geometry ([0-9x]+).*/\1/p'
share|improve this answer

You could maybe use awk substr. In your particular case :

xwininfo -root | awk '/geometry/ {print substr($2,1,8);}'

Or if you want it to work in any case :

xwininfo -root | awk '/geometry/ {print $2;}' | cut -d'+' -f1

hope this help.

share|improve this answer
Oh yes! Thank you very much! The first one worked! :) The second one produces two results: a 1 and then the resolution which would not work in this case, but still a cool statement for general knowledge. – Guest123ABC Sep 3 '14 at 18:13
you should use the answer from sylvain. it's nicer. – OldRelic Sep 3 '14 at 18:19
I've moved the grep portion into the awk command (because I can't help myself). The problem with substr is it uses fixed placements. Resolutions like 1000x1000 will break it because they're too long. – Oli Sep 3 '14 at 21:30
@Oli wow nice move. i'll not forget about that grep replacement. Thanks for the tips. You totally right about the substr, this is why i added the second command. – OldRelic Sep 4 '14 at 6:08

Others have already provided answers for the complete operation, but to answer only How do I get from 1360x768+0+0 to 1360x768? then I would recomment using cut as the simplest possible solution, e.g.

$ echo 1360x768+0+0 | cut -d+ -f1
share|improve this answer

I also tried command line screen capture examples a few weeks ago. As an alternative solution you can use

 xdpyinfo  | grep dimensions | awk -F ' ' ' { print $2 } ' 

for detecting screen resolution.

To capture screen with internal audio and microphone, you can use

 avconv -f   pulse -i default -f x11grab -r 15 -s $(xdpyinfo  | grep dimensions | awk -F ' ' ' { print $2 } ' ) -i :0.0+0,0 -acodec libmp3lame -vcodec libx264  $(date +"%m%d%Y_%H%M%S_$HOSTNAME")_screencast.mp4
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.