comparing part of header with part of detailed records.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting comparing part of header with part of detailed records.
# 1  
Old 12-02-2008
comparing part of header with part of detailed records.

Hi there,

I am lil confused with the following issue.

I have a File, which has the following header: IMSHRATE_043008_101016

a sample detailed record is :9820101 A982005000CAVG030108000000000000010169000MAR 2008
9820102 MAR 2008 D030108


I need to compare the part of Header (it is highlighted in Red Font and its a DDMMYY format ) with the Part of Detailed record (its highlighted in Yellow font and its also DDMMYY format).

The problem is there are thousands of such detailed records (on an average 50000 records) in a single file. Can anyone help me in comparing those 'part of header' with the 'part of detailed record' highlightened in Red and Yellow font in above example ?


Regards,
Cmaroju
# 2  
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";
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question