The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unique sort contents of a variable praveenbvarrier Shell Programming and Scripting 2 05-20-2008 07:12 AM
Sort and Unique in Perl deepakwins Shell Programming and Scripting 20 02-11-2008 09:25 PM
Shell script to check the unique numbers in huge data namishtiwari Shell Programming and Scripting 7 08-10-2007 09:38 AM
count data separate by comma bucci Shell Programming and Scripting 10 04-25-2007 11:54 PM
Script to count unique number of user loged in elchalateco Shell Programming and Scripting 1 09-30-2002 11:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-15-2008
amatuer_lee_3 amatuer_lee_3 is offline
Registered User
  
 

Join Date: May 2008
Posts: 53
how to sort, and count unique data all at once?

Quote:
echo "Number of unique I.P.'s: "

uniq $2 HITS | wc -l
I have this code.

In the file called HITS.hits my results are displayed liked this:

filename.hits: 35.114.42.113 Mon Nov 21 08:26:41 GMT 2005

What i want my code to do is to search all of the unique IP addresses.
so count all the adresses that appear.
but just count repeat IPs that are the same as 1.

so if my file had:

filename.hits: 11.111.11.111
filename.hits: 33.333.33.333
filename.hits: 22.222.22.222
filename.hits: 44.33.222.111
filename.hits: 11.111.11.111

the answer would be 4.
  #2 (permalink)  
Old 05-15-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
One possibility:

Code:
awk '{a[$2]}END{for(i in a){n++};print n}' file
Regards
  #3 (permalink)  
Old 05-15-2008
amatuer_lee_3 amatuer_lee_3 is offline
Registered User
  
 

Join Date: May 2008
Posts: 53
menu script

ok i have tried this and it didnt work :s

maybe i just entered it wrong.

i entered:

Quote:
awk '{a[$2]}END{for(i in a){n++};print n}' HITS
my filename is HITS that i want to search. as you quoted in your code solution. now it wont even run. i click to run in terminal and it just closes straight away
  #4 (permalink)  
Old 05-15-2008
alamitab alamitab is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 25
number of unic lines:
cat file| awk ' {print $2}' | sort | uniq | wc -l
or show the lines:
cat file| awk ' {print $2}' | sort | uniq
  #5 (permalink)  
Old 05-15-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Which OS?
Use nawk or /usr/xpg4/bin/awk on Solaris.

REgards
  #6 (permalink)  
Old 05-15-2008
amatuer_lee_3 amatuer_lee_3 is offline
Registered User
  
 

Join Date: May 2008
Posts: 53
using ubuntu, and suse10.3
  #7 (permalink)  
Old 05-15-2008
amatuer_lee_3 amatuer_lee_3 is offline
Registered User
  
 

Join Date: May 2008
Posts: 53
ok basically i am running the script so i dont think i need to cat the file as when i get to the point where i want this function the HITS file is already created so i just need to search the file to get the results.

either way i tried
Quote:
cat HITS| awk ' {print $2}' | sort | uniq | wc -l
and also

Quote:
awk '{print$2}' HITS | sort | uniq | wc -l
and even

Quote:
awk '{print$2}' | sort | uniq | wc -l HITS
none of which work.
Sponsored Links
Closed Thread

Bookmarks

Tags
linux, solaris, ubuntu

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0