Register
It is currently Tue Sep 30, 2014 5:49 am

Regular Expression Question


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Thu Dec 29, 2011 2:11 pm   

Joined: Thu Dec 29, 2011 1:54 pm
Posts: 2
I've got a one-liner script that uses HandBrake to batch encode all my home movies from .AVI to .mp4. I'd like to give the script some intelligence when it comes to stripping the extensions off the original video file names before naming the new video files. My directory is filled with.avi, .AVI, .mov and .MOV files and I'm renaming them all with .mp4.

Script:
Code:
for file in `ls $PWD`; do $(HandBrakeCLI -i $PWD/${file} -o ${PWD}/"${file%.avi}.mp4" -e x264 -b 1500 -B 192 -w 960 -l 720 -O); done


The "${file%.avi}.mp4" part, after the %, is where I'd like to insert a regular expression.

I've tried:

Code:
"${file%[(/.avi|/.AVI|/.mov|/.MOV)]}.mp4"


but that didn't work.

I also tried:

Code:
"${file%[(/.(a|A)vi)|(/.(m|M)ov)]}.mp4"


but that didn't do it either.

Could someone point me in the right direction?


Top
 Profile  
 PostPosted: Thu Dec 29, 2011 4:55 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 549
Hi,

look more closely at the man bash page, the 'Pathname Expansion' section, especially what pattern-list can do for you.

please stop using for f in `command`, it'll cause you trouble if command output something containing an IFS char; you'd better use ...Pathname Expansion ;)


Top
 Profile  
 PostPosted: Sun Jan 01, 2012 10:30 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 667
Location: Des Moines, Iowa
Try this "${file%.*}.mp4"

however...this Doesn't check to what the extention was before, it will strip the extention off ANY file in that dir, not just .avi,.mov etc..... ;)
You could use a bigger script and include a loop to check the extention and THEN run the command..... finding the extention would be something like

extension=${file##*.}

HTH's


Top
 Profile WWW  
 PostPosted: Tue Jan 03, 2012 10:53 am   

Joined: Thu Dec 29, 2011 1:54 pm
Posts: 2
Using the star did the trick. I'll also read more about pathname expansion and not use commands in my initial loops. Thank you both.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP