Need simple shell script to loop through a list, perform simple operation on each.
Posted on 2012-09-03
I can't quite get this one figured out. I'm trying to come up with a .pl or .sh "#bin/bash" script to loop through a list in a separate text file, e.g. one named lookups.txt, that has line by line entries like this:
... then execute each "host" command and pipe the results in sequence, (for each host lookup) to a file named lookupresults.txt
So at the end of the day, I will have a text file with the results for each host lookup in the source list. Of course I could change the source lookups.txt file so that it has only domains, and no "host" command in each line. Then presumably my shell script would be in charge of running the "host" command on each domain.
At first I thought I could just past in the entire series in shell, like this:
host xyz.com > lookupresults.txt
host cars.com > lookupresults.txt
host trucks.com > lookupresults.txt
host zoos.com > lookupresults.txt
But alas, the only thing I get in the lookupresults.txt file is the results for the very last lookup made, in this example, only for "host zoos.com".
Any ideas of how I could put together such a shell script to make this work?