Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can't get sed regex to work

Posted on 2014-12-15
3
Medium Priority
?
183 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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

609 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