Solved

Can't get sed regex to work

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:

757 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

18 Experts available now in Live!

Get 1:1 Help Now