Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Discarding records with duplicate fields Post 303043654 by RavinderSingh13 on Monday 3rd of February 2020 06:26:37 AM
Old 02-03-2020
Hello beca123456,

Could you please try following.

Code:
awk '/^grp1/{print;a[$2,$4,$5,$6,$7]++;next} !a[$2,$4,$5,$6,$7]++'   Input_file

Output will be as follows.

Code:
grp1    name2   firstname       M       55      item1   item1.0
grp1    name2   firstname       F       55      item1   item1.0
grp2    name1   firstname       M       55      item1   item1.0

Thanks,
R. Singh
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Records Duplicate

Hi Everyone, I have a flat file of 1000 unique records like following : For eg Andy,Flower,201-987-0000,12/23/01 Andrew,Smith,101-387-3400,11/12/01 Ani,Ross,401-757-8640,10/4/01 Rich,Finny,245-308-0000,2/27/06 Craig,Ford,842-094-8740,1/3/04 . . . . . . Now I want to duplicate... (9 Replies)
Discussion started by: ganesh123
9 Replies

2. Shell Programming and Scripting

compare fields in a file with duplicate records

Hi: I've been searching the net but didnt find a clue. I have a file in which, for some records, some fields coincide. I want to compare one (or more) of the dissimilar fields and retain the one record that fulfills a certain condition. For example, on this file: 99 TR 1991 5 06 ... (1 Reply)
Discussion started by: rleal
1 Replies

3. Shell Programming and Scripting

combine duplicate records

I have a .DAT file like below 23666483030000653-B94030001OLFXXX000000120081227 23797049900000654-E71060001OLFXXX000000220081227 23699281320000655 E71060002OLFXXX000000320081227 22885068900000652 B86860003OLFXXX592123320081227 22885068900000652 B86860003ODL-SP592123420081227... (8 Replies)
Discussion started by: kshuser
8 Replies

4. UNIX for Dummies Questions & Answers

Getting non-duplicate records

Hi, I have a file with these records abc xyz xyz pqr uvw cde cde In my o/p file , I want all the non duplicate rows to be shown. o/p abc pqr uvw Any suggestions how to do this? Thanks for the help. rs (2 Replies)
Discussion started by: rs123
2 Replies

5. UNIX for Dummies Questions & Answers

Need to keep duplicate records

Consider my input is 10 10 20 then, uniq -u will give 20 and uniq -dwill return 10. But i need the output as , 10 10 How we can achieve this? Thanks (4 Replies)
Discussion started by: pandeesh
4 Replies

6. Shell Programming and Scripting

Find duplicate based on 'n' fields and mark the duplicate as 'D'

Hi, In a file, I have to mark duplicate records as 'D' and the latest record alone as 'C'. In the below file, I have to identify if duplicate records are there or not based on Man_ID, Man_DT, Ship_ID and I have to mark the record with latest Ship_DT as "C" and other as "D" (I have to create... (7 Replies)
Discussion started by: machomaddy
7 Replies

7. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

8. Shell Programming and Scripting

Remove duplicate records

Hi, i am working on a script that would remove records or lines in a flat file. The only difference in the file is the "NOT NULL" word. Please see below example of the input file. INPUT FILE:> CREATE a ( TRIAL_CLIENT NOT NULL VARCHAR2(60), TRIAL_FUND NOT NULL... (3 Replies)
Discussion started by: reignangel2003
3 Replies

9. Shell Programming and Scripting

Duplicate records

Gents, I have a file which contends duplicate records in column 1, but the values in column 2 are different. 3099753489 3 3099753489 5 3101954341 12 3101954341 14 3102153285 3 3102153285 5 3102153297 3 3102153297 5 I will like to get something like this: output desired... (16 Replies)
Discussion started by: jiam912
16 Replies

10. Shell Programming and Scripting

Duplicate records

Gents, Please give a help file --BAD STATUS NOT RESHOOTED-- *** VP 41255/51341 in sw 2973 *** VP 41679/51521 in sw 2973 *** VP 41687/51653 in sw 2973 *** VP 41719/51629 in sw 2976 --BAD COG NOT RESHOOTED-- *** VP 41689/51497 in sw 2974 *** VP 41699/51677 in sw 2974 *** VP... (18 Replies)
Discussion started by: jiam912
18 Replies
Thread::Queue(3pm)					 Perl Programmers Reference Guide					Thread::Queue(3pm)

NAME
Thread::Queue - Thread-safe queues VERSION
This document describes Thread::Queue version 2.12 SYNOPSIS
use strict; use warnings; use threads; use Thread::Queue; my $q = Thread::Queue->new(); # A new empty queue # Worker thread my $thr = threads->create(sub { while (my $item = $q->dequeue()) { # Do work on $item } })->detach(); # Send work to the thread $q->enqueue($item1, ...); # Count of items in the queue my $left = $q->pending(); # Non-blocking dequeue if (defined(my $item = $q->dequeue_nb())) { # Work on $item } # Get the second item in the queue without dequeuing anything my $item = $q->peek(1); # Insert two items into the queue just behind the head $q->insert(1, $item1, $item2); # Extract the last two items on the queue my ($item1, $item2) = $q->extract(-2, 2); DESCRIPTION
This module provides thread-safe FIFO queues that can be accessed safely by any number of threads. Any data types supported by threads::shared can be passed via queues: Ordinary scalars Array refs Hash refs Scalar refs Objects based on the above Ordinary scalars are added to queues as they are. If not already thread-shared, the other complex data types will be cloned (recursively, if needed, and including any "bless"ings and read- only settings) into thread-shared structures before being placed onto a queue. For example, the following would cause Thread::Queue to create a empty, shared array reference via "&shared([])", copy the elements 'foo', 'bar' and 'baz' from @ary into it, and then place that shared reference onto the queue: my @ary = qw/foo bar baz/; $q->enqueue(@ary); However, for the following, the items are already shared, so their references are added directly to the queue, and no cloning takes place: my @ary :shared = qw/foo bar baz/; $q->enqueue(@ary); my $obj = &shared({}); $$obj{'foo'} = 'bar'; $$obj{'qux'} = 99; bless($obj, 'My::Class'); $q->enqueue($obj); See "LIMITATIONS" for caveats related to passing objects via queues. QUEUE CREATION
->new() Creates a new empty queue. ->new(LIST) Creates a new queue pre-populated with the provided list of items. BASIC METHODS
The following methods deal with queues on a FIFO basis. ->enqueue(LIST) Adds a list of items onto the end of the queue. ->dequeue() ->dequeue(COUNT) Removes the requested number of items (default is 1) from the head of the queue, and returns them. If the queue contains fewer than the requested number of items, then the thread will be blocked until the requisite number of items are available (i.e., until other threads <enqueue> more items). ->dequeue_nb() ->dequeue_nb(COUNT) Removes the requested number of items (default is 1) from the head of the queue, and returns them. If the queue contains fewer than the requested number of items, then it immediately (i.e., non-blocking) returns whatever items there are on the queue. If the queue is empty, then "undef" is returned. ->pending() Returns the number of items still in the queue. ADVANCED METHODS
The following methods can be used to manipulate items anywhere in a queue. To prevent the contents of a queue from being modified by another thread while it is being examined and/or changed, lock the queue inside a local block: { lock($q); # Keep other threads from changing the queue's contents my $item = $q->peek(); if ($item ...) { ... } } # Queue is now unlocked ->peek() ->peek(INDEX) Returns an item from the queue without dequeuing anything. Defaults to the the head of queue (at index position 0) if no index is specified. Negative index values are supported as with arrays (i.e., -1 is the end of the queue, -2 is next to last, and so on). If no items exists at the specified index (i.e., the queue is empty, or the index is beyond the number of items on the queue), then "undef" is returned. Remember, the returned item is not removed from the queue, so manipulating a "peek"ed at reference affects the item on the queue. ->insert(INDEX, LIST) Adds the list of items to the queue at the specified index position (0 is the head of the list). Any existing items at and beyond that position are pushed back past the newly added items: $q->enqueue(1, 2, 3, 4); $q->insert(1, qw/foo bar/); # Queue now contains: 1, foo, bar, 2, 3, 4 Specifying an index position greater than the number of items in the queue just adds the list to the end. Negative index positions are supported: $q->enqueue(1, 2, 3, 4); $q->insert(-2, qw/foo bar/); # Queue now contains: 1, 2, foo, bar, 3, 4 Specifying a negative index position greater than the number of items in the queue adds the list to the head of the queue. ->extract() ->extract(INDEX) ->extract(INDEX, COUNT) Removes and returns the specified number of items (defaults to 1) from the specified index position in the queue (0 is the head of the queue). When called with no arguments, "extract" operates the same as "dequeue_nb". This method is non-blocking, and will return only as many items as are available to fulfill the request: $q->enqueue(1, 2, 3, 4); my $item = $q->extract(2) # Returns 3 # Queue now contains: 1, 2, 4 my @items = $q->extract(1, 3) # Returns (2, 4) # Queue now contains: 1 Specifying an index position greater than the number of items in the queue results in "undef" or an empty list being returned. $q->enqueue('foo'); my $nada = $q->extract(3) # Returns undef my @nada = $q->extract(1, 3) # Returns () Negative index positions are supported. Specifying a negative index position greater than the number of items in the queue may return items from the head of the queue (similar to "dequeue_nb") if the count overlaps the head of the queue from the specified position (i.e. if queue size + index + count is greater than zero): $q->enqueue(qw/foo bar baz/); my @nada = $q->extract(-6, 2); # Returns () - (3+(-6)+2) <= 0 my @some = $q->extract(-6, 4); # Returns (foo) - (3+(-6)+4) > 0 # Queue now contains: bar, baz my @rest = $q->extract(-3, 4); # Returns (bar, baz) - (2+(-3)+4) > 0 NOTES
Queues created by Thread::Queue can be used in both threaded and non-threaded applications. LIMITATIONS
Passing objects on queues may not work if the objects' classes do not support sharing. See "BUGS AND LIMITATIONS" in threads::shared for more. Passing array/hash refs that contain objects may not work for Perl prior to 5.10.0. SEE ALSO
Thread::Queue Discussion Forum on CPAN: http://www.cpanforum.com/dist/Thread-Queue <http://www.cpanforum.com/dist/Thread-Queue> threads, threads::shared MAINTAINER
Jerry D. Hedden, <jdhedden AT cpan DOT org> LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.2 2012-10-11 Thread::Queue(3pm)
All times are GMT -4. The time now is 07:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy