Sponsored Content
Top Forums Shell Programming and Scripting Another tricky sed or awk question Post 302429842 by pseudocoder on Tuesday 15th of June 2010 06:51:05 PM
Old 06-15-2010
Code:
$ perl -F, -ane '{
                  if ( @A[0] eq "" ) { push @A, @F ; }
                  elsif ( $A[0] ne "" && $A[0] eq $F[0] ) { $A[2]="$A[2]-$F[2]"; }
                  elsif ( $A[0] ne "" && $A[0] ne $F[0] ) { print "$A[0],$A[1],$A[2],$A[3],$A[4]" ; @A=(); push @A, @F; }
                }
                 END
                {
                  print "$A[0],$A[1],$A[2],$A[3],$A[4]"; 
                }' infile

 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

Tricky File Permission Question

I'm trying to answer the following question about file permissions in Unix. Consider a file with the following permissions: rwx---r-- I am not the owner of this file, but I am a member of the group of this file. My question is: do I have read access to this file? I thought... (3 Replies)
Discussion started by: Hook
3 Replies

2. Shell Programming and Scripting

Tricky Sed

Hello. I am trying to convert occurrences of 'NULL' from a datafile. The 'NULL' occurences appears at this: |NULL| NULL|NULL| NULL|NULL| NULL|NULL| NULL| There should be 52 fields per line. I would like any occurrence of | NULL| or |NULL| to appear as '||' Currently I am using this sed... (2 Replies)
Discussion started by: bestbuyernc
2 Replies

3. Shell Programming and Scripting

Tricky script question

Hi, I'm in the midst of writing a UNIX script that sftp's files to an external host and am stuck with a problem. The problem is that the files created on my server as a order number that correlates to a sequence of directories on the remote host which is where the file should be ftp'ed. ... (3 Replies)
Discussion started by: budrito
3 Replies

4. UNIX for Dummies Questions & Answers

Tricky Quotation Question

Hi, I am at a point in my script where I defined the number of the command line parameter I would like to set a variable equal to: parameter_number=14 I would then like to set a variable equal to the correct parameter: variable=$parameter_number The issue here is that {} is required... (2 Replies)
Discussion started by: msb65
2 Replies

5. Shell Programming and Scripting

sed or awk question

Hello expert, I have an output file with few thousand lines similar like below : "Future Netmgmt" "10.99.16.0" "N" "10" "10.0.0.0" "Circuitless-IP" " " "255.255.254.0" "Future Netmgmt" "10.99.18.0" "N" "10" "10.0.0.0" "Circuitless-IP" " " "255.255.254.0" "WAAS loopbacks" "10.99.20.0"... (6 Replies)
Discussion started by: dannytrinh
6 Replies

6. Shell Programming and Scripting

Tricky sed or awk question

Hello everyone, unfortunately I am no unix nor scripting guru, which is why I am asking for help here. I am trying to reformat a .csv file using sed or awk which has the following format: a,b,C-D-E,f,g h,i,J,k,l m,n,O-P-Q-R-S,t,u v,w,X-Y,z,a It's basically a 5-field text file which has an... (7 Replies)
Discussion started by: awayand
7 Replies

7. Shell Programming and Scripting

sed tricky problem

Hi, I have a file which contains two strings: AAAAA and BBBBB I have two variables in my script: DATE="03/21/2010" aDate="20100321" I need to replace string AAAAA with variable $DATE and BBBBB with $aDate. Here is what I do sed "s/AAAAA/$DATE/" $BASIC_TMPLT | sed "s/BBBBB/$aDate/" >... (4 Replies)
Discussion started by: axed
4 Replies

8. UNIX for Dummies Questions & Answers

Tricky GREP question..

I have some large login files that I need to extract (user)@(server) from. Where it gets tricky is that there is usually more than one '@' sign on each line(although it does have a leading space if it's not part of the (user)@(server) string), I need only the (user)@(server) section, I need only... (6 Replies)
Discussion started by: Mordaris
6 Replies

9. Shell Programming and Scripting

Tricky BASH quoting question

I have some data files that I can identify by a certain pattern in the names using find. Every one of those data files has an XML file associated with it (can be multiple data files per XML file). The XML file is always up one directory from the data file(s) in a folder calledRun##### -... (12 Replies)
Discussion started by: Michael Stora
12 Replies

10. Shell Programming and Scripting

Tricky sed required

Hi All I need to put some sed together for a task and its a bit advanced for me, so I thought I'd ask if anyone here could help. I have a csv file with content like this - "","abcde","","" "'","abcde","","" "","","","1234" "'e'","","","" I need to remove any single quotes that fall... (17 Replies)
Discussion started by: steadyonabix
17 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 front-end for creating "Net::DNS::Packet" objects 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::Packet" 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 (defined $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. All rights reserved. This program is free software; you can 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.8.0 2002-05-30 Net::DNS::Update(3)
All times are GMT -4. The time now is 05:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy