Solved

Can't get sed regex to work

Posted on 2014-12-15
3
177 Views
Last Modified: 2014-12-15
Download the mp4 file:
cd /tmp
wget http://0x2a.org/leet/imagecacher/cache/1417986015.9261.mp4

Open in new window


I am trying to get the match [0-9]{1,3}x[0-9]{1,3}, please see: http://www.regexr.com/3a2vi

A correct match with the correct output is done with:
ffmpeg -i /tmp/1417986015.9261.mp4 2>&1 |grep Stream |grep Video | grep -oP '[0-9]{2,4}x[0-9]{2,4}'

Open in new window

Answer: 320x240

However, this does not work:
ffmpeg -i /tmp/1417986015.9261.mp4 2>&1 |grep Stream |grep Video | sed 's/.*\([0-9]\{3,4\}\)\w's/.*\([0-9]\{3,4\}\)\w\([0-9]\{2,4\}\).*/\1\2/'\([0-9]\{2,4\}\).*/\1\2/'

Open in new window

Answer: 320240

How to I use sed to get the answer I want? What am I doing wrong?
0
Comment
Question by:itnifl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40499902
ffmpeg -i /tmp/1417986015.9261.mp4 2>&1 |grep Stream |grep Video | sed 's/.*[^0-9]\([0-9]\{2,4\}x[0-9]\{2,4\}\).*/\1/'
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40500377
The 'why' is for one that your pattern does not contain an x but a w ;)
0
 
LVL 2

Author Comment

by:itnifl
ID: 40501184
Gerwin: No, you are mistaking.
The "\w" means "any word character" which usually means alphanumeric (letters, numbers, regardless of case) plus underscore (_)

This here shows ozo is correct, but her regex also works when using the \w instead of the x:
Sed with w and with x - same result
Ozo:
Edited my reply here. I understand your regex fully now, thanks :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question