Solved

Can't get sed regex to work

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wifi not working on Raspberry Pi 3? 2 53
Help With Shell Script Centos 6 6 52
Coding C# in Linux 8 61
how i macke server linux to server windows (rdp) 12 33
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

785 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