LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   need shell-script help (very simple) (http://www.linuxquestions.org/questions/linux-general-1/need-shell-script-help-very-simple-627455/)

oskar 03-12-2008 05:17 AM

need shell-script help (very simple)
 
I need to convert a couple of files in a folder from ogg video to dv, but I need it to keep the name, so they stay in the same numerical order, and just add an extention.

So this is the script that I use for a single file:

Code:

ffmpeg -i input.ogg -target ntsc-dv output.dv
So I have input00.ogg, input01.ogg, input02.ogg,... and so on, and I need them to be named input00.ogg.dv, input01.ogg.dv, input02.ogg.dv,... after the conversion.

I know this is ridiculously simple, but I just can't get it right... I tried to do it with find... -exec, but I just can't get behind it.

konsolebox 03-12-2008 05:35 AM

basically it can be like this:
Code:

LAST=100
for a in $(seq -w 1 ${LAST}); do
        ffmpeg -i input${a}.ogg -target ntsc-dv input${a}.ogg.dv
done

you can also have these modifications:
Code:

LAST=$(ls input*.ogg | wc -l)
and/or
Code:

        [ -e "input${a}.ogg" ] && ffmpeg -i input${a}.ogg -target ntsc-dv input${a}.ogg.dv

pwc101 03-12-2008 05:41 AM

Or, more basically, it can be:
Code:

for input in input*.ogg; do
  ffmpeg -i $input -target ntsc-dv ${input%.ogg}.dv
done

That will rename them to input00.dv, but if you really want .ogg.dv, then replace the ${input%.ogg}.dv with "$input".dv

konsolebox 03-12-2008 05:49 AM

cool script using the % operator.. i'll take a note of that :-)

pwc101 03-12-2008 05:53 AM

Quote:

Originally Posted by konsolebox (Post 3086021)
cool script using the % operator.. i'll take a note of that :-)

It's got to be the part of bash I use the most :)

oskar 03-12-2008 06:09 AM

Quote:

Originally Posted by pwc101 (Post 3086015)
That will rename them to input00.dv, but if you really want .ogg.dv, then replace the ${input%.ogg}.dv with "$input".dv

Either way is fine, of course. I thought just appending .dv would be one step less... didn't expect a single % to do the job :)

Thanks a lot to the both of you! That worked as expected.

konsolebox 03-12-2008 08:08 AM

Quote:

Originally Posted by pwc101 (Post 3086024)
It's got to be the part of bash I use the most :)

I forgot.. i was also used to doing simpler things like that in DOS and CMD shell and even in the early times of learning bash but perhaps when my scripts got a little more complicated, I forgot to think about it nomore.. Now I always think that things can't be a little more simpler. Perhaps I should go back to basics again :p


All times are GMT -5. The time now is 03:33 PM.