Iterate Over Files in Bash

Sometimes you need to whip up a dirty bash script to process through some text. I needed to iterate over my database log files that I wrote about from my last post and then output the result to a new file. I wanted the output files to have a different extension, but I wasn't sure how to get just the filename from bash, fortunately this post helped.

#!/bin/bash

for logfile in *.log
do

fn=${logfile%.*} #cut extension

echo making $fn.data...
egrep '\#\ collect|\:\=' $logfile > $fn.data 

done

If you made it this far, you should follow me on Twitter.

-JP

Want to test-drive Bitcoin without any risk? Check out my bitcoin wallet Coinbolt. It includes test coins for free.

comments powered by Disqus