[SATLUG] Bash scripting noob could use some help with a Bash script

Nate Turnage pixelnate at gmail.com
Sun May 30 15:27:08 CDT 2010


On Sun, May 30, 2010 at 9:54 AM, Don Davis <dondavis at reglue.org> wrote:

>  How do I get that to work? How do I remove the file
>
>> extension from $f?
>>
>>
> Have a look at sed, regular expressions, grep, and awk.
> They are the duct tape and flat head screwdrivers of scripting.
>
> for i in *wmv; do ffmpeg -i $i -ss 78.5 -s 640x352 -vframes 1 -an -f image2
> `echo $i | sed 's/\(.*\)\.[A-Za-z]\{3\}/\1/'`_preview.jpg; done
>
> Here -> sed 's/\(.*\)\.[A-Za-z]\{3\}/\1/'`_preview.jpg; done
>
> \. signifies escaping the dot so it's a dot and not 'any character'
>
> [A-Za-z]{3}  signifies any combination of 3 upper or lowercase letters; you
> could replace it with \.mov
>
> back ticks contain the subroutine and returns the data. $(echo $i | sed
> 's/\(.*\)\.[A-Za-z]\{3\}/\1/')_preview.jpg; done
>
> $() works as well. The preferred usage is now $(). However, I don't
> remember enough to explain why...
>
>
>

Brilliant! That worked perfectly. I'll definitely look into regex more, but
I didn't know anything about sed or awk.


Thanks,

Nate


More information about the SATLUG mailing list