Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through text file using awk??

Status
Not open for further replies.

JtheRipper

IS-IT--Management
Oct 4, 2002
274
GB
Hi there!

I am a complete newbie to awk and shell scripting and need some help pls!

I have a text file that look as follows:
ops$trr1233 1
ops$ood3333 1
ops$tri3423 0
ops$koo3333 1
.
.
.
and so on (+- 800 lines)

I want to loop through the text file, and if there is a 0 next to a name, send e-mail. I can send the mail, but my problem is that I have no idea on how to loop through the list and seperating the 2 columns.

Any help will be greatly appreciated!
Thanks,
Jaco
 
Hi,

You don't really need to use awk for this use cut e.g:

for ID in $(cut -d: -f2 myfile); do
$ID=(($ID))
if [ $ID -eq 0]; then
send mail code
fi
done

HTH


William
Software Engineer
ICQ No. 56047340
 
Hello again,

Thanks for the quick response!

I know now that I am in the wrong forum for this, but here goes anyway...

My script now looks as follows:

FILE=acc.lst
typeset ROWS=$(wc -l < $FILE )
ROWS=`expr $ROWS + 0`
NUM=`expr $ROWS - 2`
head -$NUM $FILE > temp.txt

FILE3=temp.txt

for ID in $(cut -d: -f2 $FILE3);do
$ID=(($ID))
if [ $ID -eq 0]; then
echo &quot;$ID&quot;
fi
done

I get the following error when running the file:
./jaco.mac: line 12: syntax error near unexpected token `$ID=(($ID))'
./jaco.mac: line 12: ` $ID=(($ID))'

I am not sure if fixing the above will sort out my problem though. What I want to do is:

Get 2 lists (variables), field1 and field2 with the names in field1 and the count in field2 from the txt file, then, loop through list, if field2=0, send mail &quot;field1 has a count of 0&quot;

Can this be done in a simple manner?

Thanks again in advance!
Jaco
 
Hi,

It's simply that your shell doesn't support this syntax so remove the line and change the if to:

if [ $ID -eq &quot;0&quot; ] ; then



William
Software Engineer
ICQ No. 56047340
 
Try...

while read field1 field2
do
if [ $field2 -eq 0 ]
then
echo $field1 has a count of 0
fi
done < $FILE3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top