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

Creating a file to show number of occurences.

Status
Not open for further replies.

maxcrook

Programmer
Jan 25, 2001
210
0
0
GB
I have a lot of data that throws a phone number into a log when the number has failed to load. I need to create a script the log for the phone number and creates a count next to that particular record in another file.

So far I have done:

more Fri11.errors|awk '{print $18}' |sort|uniq > max

as the phone numbers are always on the 18 column. This only creates a list of failed calls where ideally I would like the output to look like this:

Number Amount of Failures
000000000 1

If that's possible !
 
Use one more pipe :

more Fri11.errors|awk '{print $18}' |sort|uniq|wc -l > max

That will give you a line count.
 
I would separate out the phone numbers,

more Fri11.errors|awk '{print $18}' |sort |uniq> max

and then count them,

for PHONE in `cat max`
do
printf "%s %4d \n" "$PHONE" `grep $PHONE Fri11.errors | wc -l` >MaxCount
done

What this does is for every phone number in max, it searches the errors file and counts the lines. Hope this works for you.

 
It nearly worked just needed to create a file called MaxCount and add another > to the command like so.

touch MaxCount
vi MaxCount
NUMBER TOTALERRORED
:wq

for PHONE in `cat max`
do
printf "%s %4d \n" "$PHONE" `grep $PHONE Fri11.errors | wc -l` >>MaxCount
done

This worked fine thanks all for that.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top