Sponsored Content
Top Forums Shell Programming and Scripting Getting most repeated 3 lines Post 302831017 by teefa on Wednesday 10th of July 2013 04:33:41 AM
Old 07-10-2013
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print specific lines of a repeated set of data

I have a file that needs 1st line, 2nd line, and 26th line printed from every chunk of data. Each chunk of data contains 26 lines (#line+%line+24 data lines = 26 lines of data repeated). Input file: # This is a data file used for blockA (chunk 1). % 10576 A 10 0 1 04 (data1) 03 (data2)... (2 Replies)
Discussion started by: morrbie
2 Replies

2. Shell Programming and Scripting

need to print lines between repeated pattern

Hi all, I have a file that looks like this: uid=bessemsj version: 1 dn: cn=Desk SpecialAdminDesk, ou=Desks, dc=DSS,c=nl,o=Vodafone dn: cn=DSS Advisors, ou=Groups, dc=DSS,c=nl,o=Vodafone dn: cn=DSS Dispatcher,ou=Groups,dc=DSS,c=nl,o=Vodafone dn: cn=Desk Retention Desk,ou=Desks,... (13 Replies)
Discussion started by: Eman_in_forum
13 Replies

3. Shell Programming and Scripting

Deleting repeated lines by keeping only one.

Dear Buddies, Need ur help once again. I have a flat file with around 20 million lines (Huge file it is). However, many of the lines are of no use hence I want to remove it. To find and delete such lines we have certain codes written at the starting of each line. Basis that we can delete the... (2 Replies)
Discussion started by: anushree.a
2 Replies

4. Shell Programming and Scripting

Remove regularly repeated lines

How can i delete some regular repeated lines in a file? example: in_file EDGE 1 2 12 EDGE 2 3 23 EDGE 3 4 34 EDGE 5 6 56 EDGE 6 7 67 EDGE 7 8 78 EDGE 9 10 910 EDGE 10 11 1011 EDGE 11 12 1112 EDGE 13 14 1314 EDGE 14 15 1415 EDGE 15 16 1516 EDGE 17 18 1718 EDGE 18 19 1819 EDGE 19... (8 Replies)
Discussion started by: saeed.soltani
8 Replies

5. Shell Programming and Scripting

How to print the lines which are repeated 3 times in a file?

Hello All, I have a file which has repeated lines. I want to print the lines which are repeated three times. Please help. (3 Replies)
Discussion started by: ailnilanjan
3 Replies

6. Shell Programming and Scripting

Find repeated word and take sum of the second field to it ,for all the repeated words in awk

Hi below is the input file, i need to find repeated words and sum up the values of it which is second field from the repeated work.Im trying but getting no where close to it.Kindly give me a hint on how to go about it Input fruits,apple,20,fruits,mango,20,veg,carrot,12,veg,raddish,30... (11 Replies)
Discussion started by: 100bees
11 Replies

7. Shell Programming and Scripting

Compare two files with repeated lines

Hi all, I've been trying to write a script to compare two files. This is what I want: file 1: a 1 2 b 5 9 c 4 7 file 2: a a c a b Output: a 1 2 a 1 2 (2 Replies)
Discussion started by: ernesto561
2 Replies

8. Shell Programming and Scripting

Repeated lines-case sensitive

Hi, users file contains below names i have a requirement to keep only one case sensitive user. For e.g if user name is "aaa" then only aaa should be there in the file and other matching users(AAA,aaA) should be deleted. Tried multiple options but no luck can you please help. aaa abc AAA... (2 Replies)
Discussion started by: Satyak
2 Replies

9. UNIX for Beginners Questions & Answers

Export lines that have first entry repeated 5 times or above

Dears i want to extract lines only that have first entry repeated 3 times or above , ex data : -bash-3.00$ cat INTCONT-IS.CSV M205-00-106_AMDRN:1-0-6-22,12-662-4833,intContact,2016-11-15 02:32:16,50 M205-00-106_AMDRN:1-0-23-17,12-616-0462,intContact,2016-11-15 02:32:23,50... (5 Replies)
Discussion started by: is2_egypt
5 Replies

10. Shell Programming and Scripting

Remove duplicate lines which has been repeated 4 times

Remove duplicate lines which has been repeated 4 times attached test.txt below command tried and not getting expect output. for i in `cat test.txt | uniq` do num=`cat test.txt | grep $i | wc -l` echo $i $num done test.txt ... (17 Replies)
Discussion started by: Kalia
17 Replies
Class::Trigger(3pm)					User Contributed Perl Documentation				       Class::Trigger(3pm)

NAME
Class::Trigger - Mixin to add / call inheritable triggers SYNOPSIS
package Foo; use Class::Trigger; sub foo { my $self = shift; $self->call_trigger('before_foo'); # some code ... $self->call_trigger('middle_of_foo'); # some code ... $self->call_trigger('after_foo'); } package main; Foo->add_trigger(before_foo => &sub1); Foo->add_trigger(after_foo => &sub2); my $foo = Foo->new; $foo->foo; # then sub1, sub2 called # triggers are inheritable package Bar; use base qw(Foo); Bar->add_trigger(before_foo => &sub); # triggers can be object based $foo->add_trigger(after_foo => &sub3); $foo->foo; # sub3 would appply only to this object DESCRIPTION
Class::Trigger is a mixin class to add / call triggers (or hooks) that get called at some points you specify. METHODS
By using this module, your class is capable of following methods. add_trigger Foo->add_trigger($triggerpoint => $sub); $foo->add_trigger($triggerpoint => $sub); Foo->add_trigger( name => $triggerpoint, callback => sub {return undef}, abortable => 1); # no further triggers will be called. Undef will be returned. Adds triggers for trigger point. You can have any number of triggers for each point. Each coderef will be passed a reference to the calling object, as well as arguments passed in via call_trigger. Return values will be captured in list context. If add_trigger is called with named parameters and the "abortable" parameter is passed a true value, a false return value from trigger code will stop processing of this trigger point and return a "false" value to the calling code. If "add_trigger" is called without the "abortable" flag, return values will be captured by call_trigger, but failures will be ignored. If "add_trigger" is called as object method, whole current trigger table will be copied onto the object and the new trigger added to that. (The object must be implemented as hash.) my $foo = Foo->new; # this trigger ($sub_foo) would apply only to $foo object $foo->add_trigger($triggerpoint => $sub_foo); $foo->foo; # And not to another $bar object my $bar = Foo->new; $bar->foo; call_trigger $foo->call_trigger($triggerpoint, @args); Calls triggers for trigger point, which were added via "add_trigger" method. Each triggers will be passed a copy of the object as the first argument. Remaining arguments passed to "call_trigger" will be passed on to each trigger. Triggers are invoked in the same order they were defined. If there are no "abortable" triggers or no "abortable" trigger point returns a false value, "call_trigger" will return the number of triggers processed. If an "abortable" trigger returns a false value, call trigger will stop execution of the trigger point and return undef. last_trigger_results my @results = @{ $foo->last_trigger_results }; Returns a reference to an array of the return values of all triggers called for the last trigger point. Results are ordered in the same order the triggers were run. TRIGGER POINTS
By default you can make any number of trigger points, but if you want to declare names of trigger points explicitly, you can do it via "import". package Foo; use Class::Trigger qw(foo bar baz); package main; Foo->add_trigger(foo => &sub1); # okay Foo->add_trigger(hoge => &sub2); # exception FAQ
Acknowledgement: Thanks to everyone at POOP mailing-list (http://poop.sourceforge.net/). Q. This module lets me add subs to be run before/after a specific subroutine is run. Yes? A. You put various call_trigger() method in your class. Then your class users can call add_trigger() method to add subs to be run in points just you specify (exactly where you put call_trigger()). Q. Are you aware of the perl-aspects project and the Aspect module? Very similar to Class::Trigger by the look of it, but its not nearly as explicit. Its not necessary for foo() to actually say "triggers go *here*", you just add them. A. Yep ;) But the difference with Aspect would be that Class::Trigger is so simple that it's easy to learn, and doesn't require 5.6 or over. Q. How does this compare to Sub::Versive, or Hook::LexWrap? A. Very similar. But the difference with Class::Trigger would be the explicitness of trigger points. In addition, you can put hooks in any point, rather than pre or post of a method. Q. It looks interesting, but I just can't think of a practical example of its use... A. (by Tony Bowden) I originally added code like this to Class::DBI to cope with one particular case: auto-upkeep of full-text search indices. So I added functionality in Class::DBI to be able to trigger an arbitary subroutine every time something happened - then it was a simple matter of setting up triggers on INSERT and UPDATE to reindex that row, and on DELETE to remove that index row. See Class::DBI::mysql::FullTextSearch and its source code to see it in action. AUTHORS
Original idea by Tony Bowden <tony@kasei.com> in Class::DBI. Code by Tatsuhiko Miyagawa <miyagawa@bulknews.net>. Jesse Vincent added a code to get return values from triggers and abortable flag. LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Class::DBI perl v5.10.1 2009-10-11 Class::Trigger(3pm)
All times are GMT -4. The time now is 02:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy