LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-04-2013, 04:43 AM   #1
phpshell
Member
 
Registered: Nov 2012
Posts: 46

Rep: Reputation: Disabled
duplication count and show


actually I am looking for awk script or for loop to count duplication on user and get the ip for each duplication



my file


192.168.1.168 abdulatif
192.168.1.64 amr
192.168.1.98 amr

192.168.1.34 ayoup
192.168.1.35 eshal
192.168.1.21 farma
192.168.1.191 hanan
192.168.1.125 hane
192.168.1.30 hane

192.168.1.249 majde
192.168.1.40 malbak
192.168.1.227 mjut
192.168.1.117 oct



output should be

amr use 192.168.1.64 & 192.168.1.98 || hane use 192.168.1.125 & 192.168.1.30

Last edited by onebuck; 12-04-2013 at 03:16 PM. Reason: typo
 
Old 12-04-2013, 05:13 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
And your attempts so far have been ?.
 
Old 12-04-2013, 03:10 PM   #3
phpshell
Member
 
Registered: Nov 2012
Posts: 46

Original Poster
Rep: Reputation: Disabled
duplication count and show

here is my attempt
[root@proxy ~]# awk 'a[$2]++==1' test | awk '{print $2" use " $1}' | tr '\n' '|||'
amr use 192.168.1.98|hane use 192.168.1.30|
[root@proxy ~]#
 
Old 12-05-2013, 05:37 PM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
With this InFile ...
Code:
192.168.1.168 abdulatif
192.168.1.64 amr
192.168.1.98 amr
192.168.1.34 ayoup
192.168.1.35 eshal
192.168.1.21 farma
192.168.1.191 hanan
192.168.1.125 hane
192.168.1.30 hane
192.168.1.249 majde
192.168.1.40 malbak
192.168.1.227 mjut
192.168.1.117 oct
... this code ...
Code:
awk '{a[$2]=a[$2]" "$1" &"} 
  END{for (j in a) if (length(a[j])>20) print j,"use"a[j]}' $InFile  \
|sed 's/ &$//'     \
|sort              \
|paste -sd\|       \
|sed 's/|/ || /g'  \
>$OutFile
... produced this OutFile ...
Code:
amr use 192.168.1.64 & 192.168.1.98 || hane use 192.168.1.125 & 192.168.1.30
Daniel B. Martin

Last edited by danielbmartin; 12-05-2013 at 08:17 PM. Reason: Improved code
 
1 members found this post helpful.
Old 12-07-2013, 11:20 PM   #5
phpshell
Member
 
Registered: Nov 2012
Posts: 46

Original Poster
Rep: Reputation: Disabled
your the man
well done danielbmartin .
many thanks to you
 
Old 12-09-2013, 07:38 AM   #6
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by phpshell View Post
many thanks to you
You are welcome. In future, such questions should be posted in the Linux Questions Programming forum.

Daniel B. Martin
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] MySql order by COUNT and list the total count countrydj Programming 3 07-19-2012 12:21 PM
Warning: [fnn_insert] Column count doesn't match value count at row 1 in bondoq Programming 2 09-27-2011 04:11 PM
DBD::mysql::st execute failed: Column count doesn't match value count at row 1 shifter Programming 2 02-24-2010 07:42 PM
Need a way to count sub-directories and get a total count Mo-regard Linux - Newbie 1 08-14-2009 09:10 AM
Should posts in general count on your post count? Joey.Dale General 16 01-27-2004 01:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration