PDA

View Full Version : [SOLVED] For Loop help



mistertee
July 6th, 2011, 11:53 PM
Hi there, just looking for a quick assist on writing a for loop.

So I have flat file with a list of hostnames called "list1". This is just a small number of hosts within the population on my subnet. I then have a directory that contains a file for each hostname on my subnet. What I need to do is write a little for loop that looks only at the files for those hosts in "list1" that do not contain a certain attribute. What I am having problems with is defining $HOSTNAME as the hosts in "list1" and telling grep to list files that do not include the attribute.

So something like

!#/bin/bash
for
each $HOSTNAME in list1
do
grep -l 'all that do not contain this attribute' * .c
done

Can someone give me a little help please?

Thanks!!

pafoo
July 6th, 2011, 11:57 PM
for item in $(grep "myattribute" /home/list1 | cut or whatever else);
do echo $item(or whatever);
done

mistertee
July 6th, 2011, 11:59 PM
ah that makes sense. thanks!

pafoo
July 7th, 2011, 12:03 AM
Np, if it works please mark [SOLVED]