Menu

29 July 2010

Bash Script for file increment logic

Many times I use to make temporary files for certain task.
Files like

out1.ogg
out2.ogg
out11.ogg
out12.ogg
etc

Here is the logic by which you can get logic to get new filename.
for example, in this case, new filename should be  out13.ogg

How to get name of new file.

NewFileName=out$(($(find . -name "*out*.ogg" | while read FNAME; do fname=`echo $FNAME|sed 's/\.ogg$//g'|sed 's/\/out//g'|cut -c 2-` ; echo $fname ;  done | sort -n | tail -n 1)+1)).ogg

Here NewFileName will be out13.ogg

Similarly , if we want to join then all, then the command will be


cat $(find . -name "*out*.ogg" | while read FNAME; do fname=`echo $FNAME|sed 's/\.ogg$//g'|sed 's/\/out//g'|cut -c 2-` ; echo $fname ;  done | sort -n | while read NUM; do echo out$NUM.ogg; done) > final.ogg


I am trying to make a audio recorder using ffmpeg. ffmpeg cann't append files so we are doing like this.

Thanks

Posted via email from LUG@IITD Community Blog

No comments: