Sponsored Content
Top Forums Shell Programming and Scripting Remove duplicated records and update last line record counts Post 303032029 by Don Cragun on Saturday 9th of March 2019 07:04:23 PM
Old 03-09-2019
Your description and code are not clear enough to be sure that this is what you want, but it works with the sample data provided:
Code:
awk '
BEGIN {	FS = OFS = ","
}
$1 == "D" {
	if($2 in a)
		next
	a[$2]
	printed++
}
$1 == "T" {
	$2 = printed
}
1' file.CSV

Clearly field #2 is not the key to determining duplicate records, it is at least field #2 when and only when field #1 is "D". And, since you are storing the entire line into the a[] array for some reason, maybe you only want to delete identical lines instead of deleting lines with identical keys???

The above code assumes you just want to delete lines with identical keys where the key is the combination of field #1 being "D" and field #2 being unique. The second field in the line with field #1 being "T" is written with whatever was in field #2 changed to the number of lines with field #1 being "D" and field #2 being unique that have been seen before the line that has field #1 being "T". All lines that do not have field #1 being "D" or "T" are copied to the output without being counted.

You should always tell us what operating system and shell you're using when you start a new thread in this forum. The behavior of many utilities varies from operating system to operating system and the features provided by shells vary from shell to shell.

If you want to try the above code on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove duplicated xml record in a file under unix

Hi, If i have a file with xml format, i would like to remove duplicated records and save to a new file. Is it possible...to write script to do it? (8 Replies)
Discussion started by: happyv
8 Replies

2. Shell Programming and Scripting

remove duplicated columns

hi all, i have a file contain multicolumns, this file is sorted by col2 and col3. i want to remove the duplicated columns if the col2 and col3 are the same in another line. example fileA AA BB CC DD CC XX CC DD BB CC ZZ FF DD FF HH HH the output is AA BB CC DD BB CC ZZ FF... (6 Replies)
Discussion started by: kamel.seg
6 Replies

3. Shell Programming and Scripting

Help to Add and Remove Records only from first line/last line

Hi, I need help with a maybe total simple issue but somehow I am not getting it. I am not able to etablish a sed or awk command which is adding to the first line in a text and removing only from the last line the ",". The file is looking like follow: TABLE1, TABLE2, . . . TABLE99,... (4 Replies)
Discussion started by: enjoy
4 Replies

4. Shell Programming and Scripting

Sending e-mail of record counts in 3 or more files

I am trying to load data into 3 tables simultaneously (which is working fine). Then when loaded, it should count the total number of records in all the 3 input files and send an e-mail to the user. The script is working fine, as far as loading all the 3 input files into the database tables, but... (3 Replies)
Discussion started by: msrahman
3 Replies

5. Shell Programming and Scripting

Split a single record to multiple records & add folder name to each line

Hi Gurus, I need to cut single record in the file(asdf) to multile records based on the number of bytes..(44 characters). So every record will have 44 characters. All the records should be in the same file..to each of these lines I need to add the folder(<date>) name. I have a dir. in which... (20 Replies)
Discussion started by: ram2581
20 Replies

6. UNIX for Dummies Questions & Answers

Hardcoding & Record counts in a file

HI , I am having a huge comma delimiter file, I have to append the following four lines before the starting of the file through a shell script. FILE NAME = TEST_LOAD DATETIME = CURRENT DATE TIME LOAD DATE = CURRENT DATE RECORD COUNT = TOTAL RECORDS IN FILE Source data 1,2,3,4,5,6,7... (7 Replies)
Discussion started by: shruthidwh
7 Replies

7. Shell Programming and Scripting

New file should store all the 7 existing filenames and their record counts and ftp th

Hi, I need help regarding below concern. There is a script and it has 7 existing files(in a path say,. usr/appl/temp/file1.txt) and I need to create one new blank file say “file_count.txt” in the same script itself. Then the new file <file_count.txt> should store all the 7 filenames and... (1 Reply)
Discussion started by: pr293
1 Replies

8. Shell Programming and Scripting

How to Remove the new line character inbetween a record

I have a file, in which a single record spans across multiple lines, File 1 ==== 14|\n leave request \n accepted|Yes| 15|\n leave request not \n acccepted|No| I wanted to remove the '\n charecters. I used the below code (foudn somewhere in this forum) perl -e 'while (<>) { if... (1 Reply)
Discussion started by: machomaddy
1 Replies

9. Shell Programming and Scripting

How to remove duplicated lines?

Hi, if i have a file like this: Query=1 a a b c c c d Query=2 b b b c c e . . . (7 Replies)
Discussion started by: the_simpsons
7 Replies

10. Shell Programming and Scripting

Join files, omit duplicated records from one file

Hello I have 2 files, eg more file1 file2 :::::::::::::: file1 :::::::::::::: 1 fromfile1 2 fromfile1 3 fromfile1 4 fromfile1 5 fromfile1 6 fromfile1 7 fromfile1 :::::::::::::: file2 :::::::::::::: 3 fromfile2 5 fromfile2 (4 Replies)
Discussion started by: CHoggarth
4 Replies
Net::DNS::Update(3)					User Contributed Perl Documentation				       Net::DNS::Update(3)

NAME
Net::DNS::Update - Create a DNS update packet SYNOPSIS
"use Net::DNS::Update;" DESCRIPTION
"Net::DNS::Update" is a subclass of "Net::DNS::Packet", to be used for making DNS dynamic updates. Programmers should refer to RFC 2136 for the semantics of dynamic updates. WARNING: This code is still under development. Please use with caution on production nameservers. METHODS
new $packet = Net::DNS::Update->new; $packet = Net::DNS::Update->new('example.com'); $packet = Net::DNS::Update->new('example.com', 'HS'); Returns a "Net::DNS::Update" object suitable for performing a DNS dynamic update. Specifically, it creates a packet with the header opcode set to UPDATE and the zone record type to SOA (per RFC 2136, Section 2.3). Programs must use the "push" method to add RRs to the prerequisite, update, and additional sections before performing the update. Arguments are the zone name and the class. If the zone is omitted, the default domain will be taken from the resolver configuration. If the class is omitted, it defaults to IN. Future versions of "Net::DNS" may provide a simpler interface for making dynamic updates. EXAMPLES
The first example below shows a complete program; subsequent examples show only the creation of the update packet. Add a new host #!/usr/bin/perl -w use Net::DNS; use strict; # Create the update packet. my $update = Net::DNS::Update->new('example.com'); # Prerequisite is that no A records exist for the name. $update->push(pre => nxrrset('foo.example.com. A')); # Add two A records for the name. $update->push(update => rr_add('foo.example.com. 86400 A 192.168.1.2')); $update->push(update => rr_add('foo.example.com. 86400 A 172.16.3.4')); # Send the update to the zone's primary master. my $res = Net::DNS::Resolver->new; $res->nameservers('primary-master.example.com'); my $reply = $res->send($update); # Did it work? if ($reply) { if ($reply->header->rcode eq 'NOERROR') { print "Update succeeded "; } else { print 'Update failed: ', $reply->header->rcode, " "; } } else { print 'Update failed: ', $res->errorstring, " "; } Add an MX record for a name that already exists my $update = Net::DNS::Update->new('example.com'); $update->push(pre => yxdomain('example.com')); $update->push(update => rr_add('example.com MX 10 mailhost.example.com')); Add a TXT record for a name that doesn't exist my $update = Net::DNS::Update->new('example.com'); $update->push(pre => nxdomain('info.example.com')); $update->push(update => rr_add('info.example.com TXT "yabba dabba doo"')); Delete all A records for a name my $update = Net::DNS::Update->new('example.com'); $update->push(pre => yxrrset('foo.example.com A')); $update->push(update => rr_del('foo.example.com A')); Delete all RRs for a name my $update = Net::DNS::Update->new('example.com'); $update->push(pre => yxdomain('byebye.example.com')); $update->push(update => rr_del('byebye.example.com')); Perform a signed update my $key_name = 'tsig-key'; my $key = 'awwLOtRfpGE+rRKF2+DEiw=='; my $update = Net::DNS::Update->new('example.com'); $update->push(update => rr_add('foo.example.com A 10.1.2.3')); $update->push(update => rr_add('bar.example.com A 10.4.5.6')); $update->sign_tsig($key_name, $key); Another way to perform a signed update my $key_name = 'tsig-key'; my $key = 'awwLOtRfpGE+rRKF2+DEiw=='; my $update = Net::DNS::Update->new('example.com'); $update->push(update => rr_add('foo.example.com A 10.1.2.3')); $update->push(update => rr_add('bar.example.com A 10.4.5.6')); $update->push(additional => Net::DNS::RR->new("$key_name TSIG $key")); Perform a signed update with a customized TSIG record my $key_name = 'tsig-key'; my $key = 'awwLOtRfpGE+rRKF2+DEiw=='; my $tsig = Net::DNS::RR->new("$key_name TSIG $key"); $tsig->fudge(60); my $update = Net::DNS::Update->new('example.com'); $update->push(update => rr_add('foo.example.com A 10.1.2.3')); $update->push(update => rr_add('bar.example.com A 10.4.5.6')); $update->push(additional => $tsig); BUGS
This code is still under development. Please use with caution on production nameservers. COPYRIGHT
Copyright (c) 1997-2002 Michael Fuhr. Portions Copyright (c) 2002-2004 Chris Reinhardt. All rights reserved. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perl(1), Net::DNS, Net::DNS::Resolver, Net::DNS::Header, Net::DNS::Packet, Net::DNS::Question, Net::DNS::RR, RFC 2136, RFC 2845 perl v5.12.1 2009-12-30 Net::DNS::Update(3)
All times are GMT -4. The time now is 07:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy