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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use shell scripting to "cut" a list into columns

Status
Not open for further replies.

JtheRipper

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

I am quite new to shell scripting and need some help with the following:

I have a text file that looks like the following:

ops$ret11111 1
ops$abs12344 1
ops$kke23412 1
ops$het29845 0
ops$hyt24556 0
ops$uye23322 1
.
.
.and so on...(800+lines)

I want to loop through the list and create 2 variables, field1 with the names and field2 with the count.
If field2 = 0
then send email "field1 has a count of 0"
fi

My script 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

--here i must start to go through $FILE3 and look for count of 0--

Any help on this will be appreciated!

Thanks,
Jaco
 
## ksh
## this could be one approach

Emsg=&quot;\n&quot;;
while read usr cnt
do
# print $usr has cnt $cnt
if [ $cnt = 0 ]
then
print $usr has count of $cnt
Emsg=&quot;$Emsg\n$usr&quot;;
fi
done < $FILE3

print $Emsg | mailx -s&quot;Zero count users enclosed&quot; $DISTRO
~
HtH
bharix
 
another approach...

#!/bin/sh

while read line
do
name=`echo $line | awk '{print $1}'`
number=`echo $line | awk '{print $NF}'`
if test &quot;$number&quot; -eq &quot;0&quot;
then
echo &quot;$line&quot; | mail -s &quot;Field 1 has count of 0&quot; $USER
fi
done < acc.lst

 
Hi there!

Thanks for all the help so far!

I have trouble even going through the text file getting field1 and field2!

I suppose the algorithm might look something like this for what I want to do:

for i in textfile_length
begin
field1 = line_column1;
field2 = line_column2;

if field2 == 0
then
begin
mail &quot;field1 has a count of 0&quot;
end;
end;

I do not know how to write the above in shell scripting.

All help appreciated!
Thnx,
Jaco

 
Try this one :

for i in `cat 1.txt|tr -s ' ' '~'|cut -d' ' -f1-2`
do
field1=`echo $i|cut -d'~' -f1`
field2=`echo $i|cut -d'~' -f2`
if [ $field2 -eq 0 ]; then
echo &quot;$field1 has a count of zero&quot; >> tempfile
fi
done
mailx -s &quot;Subject of mail&quot; mailid < tempfile
rm tempfile

Regards
Ajay.
 
My script works perfectly now thanks to all the help I got!


Thank you all for the input
Jaco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top