BashScripts.org
http://bashscripts.org/forum/

Regular Expression Question
http://bashscripts.org/forum/viewtopic.php?f=15&t=1521
Page 1 of 1

Author:  jimper [ Thu Dec 29, 2011 2:11 pm ]
Post subject:  Regular Expression Question

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?

Author:  Watael [ Thu Dec 29, 2011 4:55 pm ]
Post subject:  Re: Regular Expression Question

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 ;)

Author:  crouse [ Sun Jan 01, 2012 10:30 am ]
Post subject:  Re: Regular Expression Question

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

Author:  jimper [ Tue Jan 03, 2012 10:53 am ]
Post subject:  Re: Regular Expression Question

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.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com