Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Discarding records with duplicate fields Post 303043653 by beca123456 on Monday 3rd of February 2020 06:19:13 AM
Old 02-03-2020
Discarding records with duplicate fields

Hi,

My input looks like this (tab-delimited):
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
grp2	name2	firstname	M	55	item1	item1.0

Using awk, I am trying to discard the records with common fields 2, 4, 5, 6, 7 only for records from 'grp2' (field $1; i.e. records starting with 'grp1' should be kept no matter what) in order to get this output:
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

Here is my code, but I don't see what is wrong with it.
Code:
awk '
BEGIN{FS=OFS="\t"}
{
    a[$2 FS $4 FS $5 FS $6 FS $7]

    if($1 ~ /grp2/){
        if(a[$2 FS $4 FS $5 FS $6 FS $7]++==0){
            print $0
         }
    }
    else{
        print $0
    }
}' input.tab

Any help would be greatly appreciated.
 

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
Perl::Critic::Utils::POD(3)				User Contributed Perl Documentation			       Perl::Critic::Utils::POD(3)

NAME
Perl::Critic::Utils::POD - Utility functions for dealing with POD. SYNOPSIS
use Perl::Critic::Utils::POD qw< get_pod_section_from_file >; my $synopsis = get_pod_section_from_file('Perl/Critic/Utils/POD.pm', 'SYNOPSIS'); my $see_also = get_pod_section_from_filehandle($file_handle, 'SEE ALSO'); my $see_also_content = trim_pod_section($see_also); # "Utility functions for dealing with POD." my $module_abstract = get_module_abstract_from_file('Perl/Critic/Utils/POD.pm'); my $module_abstract = get_module_abstract_from_filehandle($file_handle); DESCRIPTION
Provides means of accessing chunks of POD. INTERFACE SUPPORT
This is considered to be a public module. Any changes to its interface will go through a deprecation cycle. IMPORTABLE SUBROUTINES
"get_pod_file_for_module( $module_name )" Figure out where to find the POD for the parameter. This depends upon the module already being loaded; it will not find the path for arbitrary modules. If there is a file with a ".pod" extension next to the real module location, it will be returned in preference to the actual module. "get_raw_pod_section_from_file( $file_name, $section_name )" Retrieves the specified section of POD (i.e. something marked by "=head1") from the file. This is uninterpreted; escapes are not processed and any sub-sections will be present. E.g. if the content contains "C<$x>", the return value will contain "C<$x>". Returns nothing if no such section is found. Throws a Perl::Critic::Exception::IO if there's a problem with the file. "get_raw_pod_section_from_filehandle( $file_handle, $section_name )" Does the same as "get_raw_pod_section_from_file()", but with a file handle. "get_raw_pod_section_from_string( $source, $section_name )" Does the same as "get_raw_pod_section_from_file()", but with a string that contains the raw POD. "get_raw_pod_section_for_module( $module_name, $section_name )" Does the same as "get_raw_pod_section_from_file()", but with a module name. Throws a Perl::Critic::Exception::Generic if a file containing POD for the module can't be found. "get_pod_section_from_file( $file_name, $section_name )" Retrieves the specified section of POD (i.e. something marked by "=head1") from the file. This is interpreted into plain text. Returns nothing if no such section is found. Throws a Perl::Critic::Exception::IO if there's a problem with the file. "get_pod_section_from_filehandle( $file_handle, $section_name )" Does the same as "get_pod_section_from_file()", but with a file handle. "get_pod_section_from_string( $source, $section_name )" Does the same as "get_pod_section_from_file()", but with a string that contains the raw POD. "get_pod_section_for_module( $module_name, $section_name )" Does the same as "get_pod_section_from_file()", but with a module name. Throws a Perl::Critic::Exception::Generic if a file containing POD for the module can't be found. "trim_raw_pod_section( $pod_section )" Returns a copy of the parameter, with any starting "=item1 BLAH" removed and all leading and trailing whitespace (including newlines) removed after that. For example, using one of the "get_raw_pod_section_from_*" functions to get the "NAME" section of this module and then calling "trim_raw_pod_section()" on the result would give you "Perl::Critic::Utils::POD - Utility functions for dealing with POD.". "trim_pod_section( $pod_section )" Returns a copy of the parameter, with any starting line removed and leading blank lines and trailing whitespace (including newlines) removed after that. Note that only leading whitespace on the first real line of the section will remain. Since this cannot count upon a "=item1" marker, this is much less reliable than "trim_raw_pod_section()". "get_raw_module_abstract_from_file( $file_name )" Attempts to parse the "NAME" section of the specified file and get the abstract of the module from that. If it succeeds, it returns the abstract. If it fails, either because there is no "NAME" section or there is no abstract after the module name, returns nothing. If it looks like there's a malformed abstract, throws a Perl::Critic::Exception::Fatal::Generic. Example "well formed" "NAME" sections without abstracts: Some::Module Some::Other::Module - Example "NAME" sections that will result in an exception: Some::Bad::Module This has no hyphen. Some::Mean::Module -- This has double hyphens. Some::Nasty::Module - This one attempts to span multiple lines. "get_raw_module_abstract_from_filehandle( $file_handle )" Does the same as "get_raw_module_abstract_from_file()", but with a file handle. "get_raw_module_abstract_from_string( $source )" Does the same as "get_raw_module_abstract_from_file()", but with a string that contains the raw POD. "get_raw_module_abstract_for_module( $module_name )" Does the same as "get_raw_module_abstract_from_file()", but for a module name. "get_module_abstract_from_file( $file_name )" Does the same as "get_raw_module_abstract_from_file()", but with escapes interpreted. "get_module_abstract_from_filehandle( $file_handle )" Does the same as "get_module_abstract_from_file()", but with a file handle. "get_module_abstract_from_string( $source )" Does the same as "get_module_abstract_from_file()", but with a string that contains the raw POD. "get_module_abstract_for_module( $module_name )" Does the same as "get_module_abstract_from_file()", but for a module name. AUTHOR
Elliot Shank <perl@galumph.com> COPYRIGHT
Copyright (c) 2008-2011 Elliot Shank. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.16.3 2014-06-09 Perl::Critic::Utils::POD(3)
All times are GMT -4. The time now is 01:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy