Solved

Can't get sed regex to work

Posted on 2014-12-15
3
171 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
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 37

Expert Comment

by:Gerwin Jansen
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This is about my first experience with programming Arduino.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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.

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now