Getting most repeated 3 lines | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Getting most repeated 3 lines

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-10-2013
teefa teefa is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 17 February 2014, 12:37 AM EST
Posts: 81
Thanks: 31
Thanked 0 Times in 0 Posts
Getting most repeated 3 lines

Hi all
if i want to get the 3 lines of the most repeated lines here

Code:
tony,1,x
tony,1,x
tony,2,x
tony,2,x
tony,3,x
tony,4,x
tony,5,x
adam,1,y

to get output

Code:
tony,1,x
tony,2,x
tony3,x
adam,1,y


Code:
ive tried to uniq -c | /usr/xpg4/bin/awk -F"," '!a[$1]++'

but it gets only first one i need first 3
Sponsored Links
    #2  
Old 07-10-2013
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 5 December 2014, 6:39 AM EST
Location: INDIA, Bangalore
Posts: 2,049
Thanks: 16
Thanked 106 Times in 102 Posts
I am unable to understand your full requirement..
what does this mean? "3 lines of the most repeated lines "
why out of three lines below u selected tony3,x?
tony,3,x
tony,4,x
tony,5,x
Sponsored Links
    #3  
Old 07-10-2013
gokcell gokcell is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 1 September 2013, 7:17 AM EDT
Location: Saudi Arabia
Posts: 14
Thanks: 0
Thanked 3 Times in 3 Posts
Count to lines

Hi,

This can help you,


Code:
 cat file1
tony,1,x
tony,1,x
tony,2,x
tony,2,x
tony,3,x
tony,4,x
tony,5,x
adam,1,y


Code:
cat file1 | sort | uniq -c | awk '{print $2"\t""COUNT"$1}'
adam,1,y        COUNT1
tony,1,x        COUNT2
tony,2,x        COUNT2
tony,3,x        COUNT1
tony,4,x        COUNT1
tony,5,x        COUNT1

Then second step


Code:
cat file1 | sort | uniq -c | awk '{print $2"\t""COUNT"$1}' | awk '{print $2}' | sort | uniq
COUNT1
COUNT2

Next step so search COUNT2 parameters


Code:
cat file1 | sort | uniq -c | awk '{print $2"\t""COUNT"$1}' | grep "COUNT2"
tony,1,x        COUNT2
tony,2,x        COUNT2

Unix is life. Always try to find easy way.

Regards,
Goksel Yangin
Computer Engineer
    #4  
Old 07-10-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 19 December 2014, 2:53 AM EST
Location: St. Gallen, Switzerland
Posts: 6,251
Thanks: 126
Thanked 455 Times in 414 Posts
You posted nearly the same question here:

http://www.unix.com/shell-programmin...ed-column.html

Please do not open up another thread just because of such an unsignificant difference. Else you get infractions for double posts. Keep that in mind, thanks.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print the lines which are repeated 3 times in a file? ailnilanjan Shell Programming and Scripting 3 05-05-2013 04:11 AM
Remove regularly repeated lines saeed.soltani Shell Programming and Scripting 8 01-05-2013 02:21 AM
Deleting repeated lines by keeping only one. anushree.a Shell Programming and Scripting 2 09-25-2012 07:12 AM
need to print lines between repeated pattern Eman_in_forum Shell Programming and Scripting 13 09-06-2012 11:24 AM
Print specific lines of a repeated set of data morrbie Shell Programming and Scripting 2 03-14-2012 06:34 AM



All times are GMT -4. The time now is 06:57 PM.