Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a script over multiple files in unix

Tags:

shell

unix

Started to learn some shell scripting. I have a perl script that runs on one file. How would I write a shell script to run the perl script a bunch of times on all files with keyword "filename" in it?

So in English,

for /filename/ in filenames  
    perl myscript.pl completefilename

Thanks.

like image 872
Dirk Avatar asked Jul 06 '09 16:07

Dirk


2 Answers

find . -name "filename*" -exec perl myscript.pl '{}' \; 
like image 110
Bob F. Avatar answered Oct 06 '22 20:10

Bob F.


for i in $(\ls -d filenames)
do
    perl myscript.pl $i
done

The backslash in front of the 'ls' command is to temporarily disable any aliases.

HTH

like image 33
Rob Wells Avatar answered Oct 06 '22 19:10

Rob Wells