![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk - Counting number of similar lines | dhanamurthy | Shell Programming and Scripting | 8 | 05-16-2008 03:00 AM |
| Duplicate lines in the file | guptan | UNIX for Advanced & Expert Users | 3 | 05-18-2006 02:28 AM |
| Counting Number of times a File is accessed | pathanjalireddy | Shell Programming and Scripting | 1 | 04-11-2005 06:49 AM |
| counting the number of lines | nayeemmz | Linux | 6 | 01-19-2005 08:37 AM |
| Counting the number of lines in ASCII file | alarmcall | Shell Programming and Scripting | 8 | 08-26-2003 03:53 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Counting The Number Of Duplicate Lines In a File
Hello. First time poster here. I have a huge file of IP numbers. I am trying to output only the class b of the IPs and rank them by most common and output the total # of duplicate class b's before the class b. An example is below:
12.107.1.1 12.107.9.54 12.108.3.89 12.109.109.4 12.109.6.3 Output would be: 2 12.107 2 12.109 Thanks for the help Crunchtime |
| Forum Sponsor | ||
|
|
|
|||
|
As you can see, a simple script does the trick
[dummy806]@@ecar0o:/opt/oracle/TOOLS/generic_unix/scripts> cat ttt 12.107.1.1 12.107.9.54 12.108.3.89 12.109.109.4 12.109.6.3 [dummy806]@@ecar0o:/opt/oracle/TOOLS/generic_unix/scripts> for i in `cat ttt | cut -d"." -f1,2 | uniq` more>do more> num=`cat ttt | grep $i | wc -l` more> if (( $num > 1 )) more> then more> echo $num $i more> fi more>done 2 12.107 2 12.109 |