Sponsored Content
Top Forums Shell Programming and Scripting comparing part of header with part of detailed records. Post 302263599 by summer_cherry on Tuesday 2nd of December 2008 03:45:26 AM
Old 12-02-2008
Hi ,

Is the yellow highlighted section is fixed in all your detail lines?

anyway , below perl may help you a little

input(a.txt):
Code:
IMSHRATE_043008_101016
9820101 A982005000CAVG 030108 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
9820101 A982005000CAVG 030109 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
9820101 A982005000CAVG 043008 000000000000010169000MAR 2008 9820102 MAR 2008 D030108

output:
Code:
MSHRATE_043008_101016
9820101 A982005000CAVG 030108 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
Smaller than header
9820101 A982005000CAVG 030109 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
Bigger than header
9820101 A982005000CAVG 043008 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
Equal with header

code:
Code:
open FH,"<a.txt" or die "Can not open file\n";
my @arr=<FH>;
close FH;
$arr[0]=~m/(.*)_([0-9][0-9])([0-9][0-9])([0-9][0-9])_(.*)/;
$header=$4.$2.$3;
print $arr[0];
for($i=1;$i<=$#arr;$i++){
	my @temp=split(" ",$arr[$i]);
	$temp[2]=~m/([0-9][0-9])([0-9][0-9])([0-9][0-9])/;
	my $body=$3.$1.$2;
	print $arr[$i],($body>$header)?"Bigger than header\n":($body==$header)?"Equal with header\n":"Smaller than header\n";
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to extract duplicate records with associated header record

All, I have a task to search through several hundred files and extract duplicate detail records and keep them grouped with their header record. If no duplicate detail record exists, don't pull the header. For example, an input file could look like this: input.txt HA D1 D2 D2 D3 D4 D4... (17 Replies)
Discussion started by: run_eim
17 Replies

2. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies

3. UNIX for Dummies Questions & Answers

pull date from header and append to all records

I did some searches, but couldn't really find what I'm looking for. I have a file formatted as below: BOF ABC CO - XYZ COMM DATA OF 07/05/2011 EBA00000001 sdfa rtyus uyml EBB00000001 54682 984w3 EBA00000002 mkiyuasdf 98234 I want to pull the date from the header record and add it... (4 Replies)
Discussion started by: keeferb
4 Replies

4. Shell Programming and Scripting

Specific Header after every 30 records

Hi All, I have got a requirement. I have a source file, EMPFULL.txt and I need to split the data for every 30 records and place a Typical Header as below with system and page number too. 2012.01.03 Employee Dept Report 1... (6 Replies)
Discussion started by: srk409
6 Replies

5. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

6. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

7. Shell Programming and Scripting

Copy header values into records

I'm using a shell script to manipulate a data file. I have a large file with two sets of data samples (tracking memory consumption) taken over a long period of time, so I have many samples. The problem is that all the data is in the same file so that each sample contains two sets of data.... (2 Replies)
Discussion started by: abercrom
2 Replies

8. Shell Programming and Scripting

How to add a status once a step is complete on the header part of a menu?

Hi Guru's, i am creating a script that will update menu of either complete or failed. #!/bin/bash choice=0 while do echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "" echo " ###############################################" echo " # Choose... (3 Replies)
Discussion started by: reignangel2003
3 Replies

9. UNIX for Beginners Questions & Answers

Help in printing records where there is a 'header' in the first record ???

Hi, I have a backup report that unfortunately has some kind of hanging indent thing where the first line contains one column more than the others I managed to get the output that I wanted using awk, but just wanting to know if there is short way of doing it using the same awk Below is what... (2 Replies)
Discussion started by: newbie_01
2 Replies

10. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies
Net::DNS::Header(3)					User Contributed Perl Documentation				       Net::DNS::Header(3)

NAME
Net::DNS::Header - DNS packet header SYNOPSIS
use Net::DNS; $packet = new Net::DNS::Packet; $header = $packet->header; DESCRIPTION
"Net::DNS::Header" represents the header portion of a DNS packet. METHODS
new $header = new Net::DNS::Header($packet); Constructor method which returns a "Net::DNS::Header" object representing the header section of the specified packet. decode $header->decode($data); Decodes the header record at the start of a DNS packet. The argument is a reference to the packet data. encode $header->encode($data); Returns the header data in binary format, appropriate for use in a DNS packet. string print $packet->header->string; Returns a string representation of the packet header. id print "query id = ", $packet->header->id, " "; $packet->header->id(1234); Gets or sets the query identification number. A random value is assigned if the argument value is undefined. opcode print "query opcode = ", $packet->header->opcode, " "; $packet->header->opcode("UPDATE"); Gets or sets the query opcode (the purpose of the query). rcode print "query response code = ", $packet->header->rcode, " "; $packet->header->rcode("SERVFAIL"); Gets or sets the query response code (the status of the query). qr print "query response flag = ", $packet->header->qr, " "; $packet->header->qr(0); Gets or sets the query response flag. aa print "answer is ", $packet->header->aa ? "" : "non-", "authoritative "; $packet->header->aa(0); Gets or sets the authoritative answer flag. tc print "packet is ", $packet->header->tc ? "" : "not ", "truncated "; $packet->header->tc(0); Gets or sets the truncated packet flag. rd print "recursion was ", $packet->header->rd ? "" : "not ", "desired "; $packet->header->rd(0); Gets or sets the recursion desired flag. ra print "recursion is ", $packet->header->ra ? "" : "not ", "available "; $packet->header->ra(0); Gets or sets the recursion available flag. z Unassigned bit, should always be zero. ad print "The result has ", $packet->header->ad ? "" : "not", "been verified "; Relevant in DNSSEC context. (The AD bit is only set on answers where signatures have been cryptographically verified or the server is authoritative for the data and is allowed to set the bit by policy.) cd print "checking was ", $packet->header->cd ? "not" : "", "desired "; $packet->header->cd(0); Gets or sets the checking disabled flag. qdcount, zocount print "# of question records: ", $packet->header->qdcount, " "; Gets the number of records in the question section of the packet. In dynamic update packets, this field is known as "zocount" and refers to the number of RRs in the zone section. ancount, prcount print "# of answer records: ", $packet->header->ancount, " "; Returns the number of records in the answer section of the packet which may, in the case of corrupt packets, differ from the actual number of records. In dynamic update packets, this field is known as "prcount" and refers to the number of RRs in the prerequisite section. nscount, upcount print "# of authority records: ", $packet->header->nscount, " "; Returns the number of records in the authority section of the packet which may, in the case of corrupt packets, differ from the actual number of records. In dynamic update packets, this field is known as "upcount" and refers to the number of RRs in the update section. arcount, adcount print "# of additional records: ", $packet->header->arcount, " "; Returns the number of records in the additional section of the packet which may, in the case of corrupt packets, differ from the actual number of records. In dynamic update packets, this field is known as "adcount". EDNS Protocol Extensions do print "DNSSEC_OK flag was ", $packet->header->do ? "not" : "", "set "; $packet->header->do(1); Gets or sets the EDNS DNSSEC OK flag. Extended rcode EDNS extended rcodes are handled transparently by $packet->header->rcode(). UDP packet size $udp_max = $packet->edns->size; $udp_max = $packet->header->size; EDNS offers a mechanism to advertise the maximum UDP packet size which can be assembled by the local network stack. UDP size advertisement can be viewed as either a header extension or an EDNS feature. Endless debate is avoided by supporting both views. edns $header = $packet->header; $version = $header->edns->version; @options = $header->edns->options; $option = $header->edns->option(n); $udp_max = $packet->edns->size; Auxiliary function which provides access to the EDNS protocol extension OPT RR. COPYRIGHT
Copyright (c)1997-2002 Michael Fuhr. Portions Copyright (c)2002-2004 Chris Reinhardt. Portions Copyright (c)2012 Dick Franks. 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, Net::DNS, Net::DNS::Packet, Net::DNS::RR::OPT RFC 1035 Section 4.1.1 perl v5.16.3 2012-12-28 Net::DNS::Header(3)
All times are GMT -4. The time now is 01:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy