As an ArgoUML contributor I'm going to blog my activities here, so that they may draw interest by other developers or help other developers when doing tasks similar to what I've done. AND(!) the grand vision that makes an Argonaut what he is, TO THRIVE IN THE BIG DANGEROUS WORLD, TAKING THE Argo TO A GOOD SHORE ;-))

Friday, September 04, 2009

bash hints – for loops

Today I had to process some files in a similar way in a bash shell. After trying using pipes, I reverted to for loops. First iterating for all files in a directory and extracting its contents (they were *.tar.bz2):

(...)/pcl-book/c23-spam/sa-pub-corpus> ls 
20030228_easy_ham_2.tar.bz2  20030228_hard_ham.tar.bz2  20030228_spam.tar.bz2 
20030228_easy_ham.tar.bz2    20030228_spam_2.tar.bz2
(...)/pcl-book/c23-spam/sa-pub-corpus> for f in *; do tar -xjf $f; done

Then, I discovered that the archives contained a file which I didn't wanted, so, I removed the files (the files were named “cmds”):

(...)/pcl-book/c23-spam/sa-pub-corpus> ls 
20030228_easy_ham_2.tar.bz2  20030228_hard_ham.tar.bz2  20030228_spam.tar.bz2  easy_ham_2/  spam/ 
20030228_easy_ham.tar.bz2    20030228_spam_2.tar.bz2    easy_ham/              hard_ham/    spam_2/
(...)/pcl-book/c23-spam/sa-pub-corpus> for f in `ls --ignore=2003*`; do `rm $f\cmds`; done

No comments:

Reader Shared items

Followers