The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Hash Question in Perl deadletter Shell Programming and Scripting 6 07-17-2008 06:07 PM
Perl Hash Harikrishna Shell Programming and Scripting 1 06-04-2008 08:03 AM
Perl Hash Harikrishna Shell Programming and Scripting 1 06-03-2008 12:45 AM
Hash in perl Harikrishna Shell Programming and Scripting 1 06-02-2008 05:00 AM
hash,array and perl new2ss Shell Programming and Scripting 3 05-23-2007 12:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-14-2007
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 139
Question perl hash ..confused

hi
i want to generate standard file from log file. log file containts information about files which are copied to testing region. log files looks as follows

Code:
date           time          label                file                 ver      date 
2007-12-13 20:25        SPR 30417       CI0051.COB      1.35    20071213        /Clients/NCB/BANCS-24/cob/CI0051.COB    /BASE/src/CI0051.COB
2007-12-13 20:35        SPR 30418       060658.xml      1.2     20071213        /Clients/NCB/Frontend/xml/Transactions/060658.xml       /FEBase/xml/Transactions/060658.xml
2007-12-13 20:39        SPR 30417       IN0011.COB      1.7     20071213        /Clients/NCB/BANCS-24/cob/IN0011.COB    /BASE/src/IN0011.COB
2007-12-13 21:17        SPR 30417       032001.htm      1.1     20071213        /Clients/NCB/Frontend/html/032001.htm   /FEBase/html/032001.htm

now there can be many entries for single file but with different versions but i want that only file with latest version should be present in new file.
i am using perl for this there are total 5 scripts to do final job 4 are ready i am stuck with this one to get unique components only

for eg if input file is

Code:
.....IN0000.COB     1.2     ......
.....login.htm         1.1     .....
.....IN0000.COB     1.3     ....
           .
           .

oputfile should be

Code:
.....login.htm         1.1     .....
.....IN0000.COB     1.3     ....
                 .
                 .

i have hash in which i store file name and its key is version no i check entry of file in hash if its there then i comaprare otherwise i add in hash but what i want is that other information on that is importatnt for same file ii may change also like version label so final file should be list of uniq files with all other information intact as shown in first file.
  #2 (permalink)  
Old 12-14-2007
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
I'm not totally sure what you want to do. But to limit display of lines with identical filename to the highest version only, you can put the line into the hash and after filtering you will get what you want. Here is an example (5 lines into 4):


Code:
@lines = split(/\n/, "2007-12-13 20:25        SPR 30417       CI0051.COB      1.35    20071213        /Clients/NCB/BANCS-24/cob/CI0051.COB    /BASE/src/CI0051.COB
2007-12-13 20:35        SPR 30418       060658.xml      1.2     20071213        /Clients/NCB/Frontend/xml/Transactions/060658.xml       /FEBase/xml/Transactions/060658.xml
2007-12-19 20:35        SPR 30418       060658.xml      1.12     20071219        /Clients/NCB/Frontend/xml/Transactions/060658.xml       /FEBase/xml/Transactions/060658.xml
2007-12-13 20:39        SPR 30417       IN0011.COB      1.7     20071213        /Clients/NCB/BANCS-24/cob/IN0011.COB    /BASE/src/IN0011.COB
2007-12-13 21:17        SPR 30417       032001.htm      1.1     20071213        /Clients/NCB/Frontend/html/032001.htm   /FEBase/html/032001.htm");

sub ver_compare {
my ($a2, $b2) = map { [split(/\./, $_)] } @_;
return ($a2->[0] <=> $b2->[0] || $a2->[1] <=> $b2->[1]);
}

%line_maxvers = ();
foreach $line (@lines) {
($date, $time, $label1, $label2, $fn, $ver) = split(/\s+/, $line);
$line_maxvers{$fn} = [$ver, $line] if (!$line_maxvers{$fn} || ver_compare($ver, $line_maxvers{$fn}) > 0);
}

foreach (values %line_maxvers) {
print $_->[1], "\n";
}

  #3 (permalink)  
Old 12-15-2007
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 139
Question

hi
thanks cbkihong for ur reply

got what is the error in my code following link provided good help

Perl Hash Howto


my file which is input to this script :

Code:
2007-12-13 20:25	SPR 30417	CI0051.COB	1.35	20071213	lanthanum	abcdefg	/ABC/efg/BANCS-24/cob/CI0051.COB	/BASE/src/CI0051.COB
2007-12-13 20:35	SPR 30418	060658.xml	1.2	20071213	lanthanum	abcdefg	/ABC/efg/Frontend/xml/Transactions/060658.xml	/FEBase/xml/Transactions/060658.xml
2007-12-13 20:39	SPR 30417	IN0011.COB	1.6	20071213	lanthanum	abcdefg	/ABC/efg/BANCS-24/cob/IN0011.COB	/BASE/src/IN0011.COB
2007-12-13 21:17	SPR 30417	032001.htm	1.1	20071213	lanthanum	abcdefg	/ABC/efg/Frontend/html/032001.htm	/FEBase/html/032001.htm
2007-12-13 23:00	SPR 30251	CommissionFetch.htc	1.5	20071213	Khalid	abcdefg	/ABC/efg/Core/htc/FlowComponents/CommissionFetch.htc	/FEBase/htc/FlowComponents/CommissionFetch.htc
2007-12-13 20:39	SPR 30410	IN0011.COB	1.7	20071213	lanthanum	abcdefg	/ABC/efg/BANCS-24/cob/IN0011.COB	/BASE/src/IN0011.COB

output i am getting with this error :

Code:
# display from subroutine stored indicates version stored in hash and read is one which need to be compared 
# stored : HASH(0x4014f620) 	 read : 1.7
# HASH(0x4014f620)0000000000000000000000000000 :1st sting 
#00010007000000000000000000000000 :2nd sting 
/Clients/NCB/Frontend/html/032001.htm	1.1	20071213	SPR 30417	/FEBase/html/032001.htm
/Clients/NCB/Frontend/xml/Transactions/060658.xml	1.2	20071213	SPR 30418	/FEBase/xml/Transactions/060658.xml
/Clients/NCB/BANCS-24/cob/CI0051.COB	1.35	20071213	SPR 30417	/BASE/src/CI0051.COB
/Clients/NCB/Core/htc/FlowComponents/CommissionFetch.htc	1.5	20071213	SPR 30251	/FEBase/htc/FlowComponents/CommissionFetch.htc
Can't use string ("CommissionFetch.htc") as a HASH ref while "strict refs" in use at test.pl line 56, <PROLOG> line 6.

Now getting the proper output

Code:
/ABC/efg/Frontend/html/032001.htm   1.1     20071213        SPR 30417       /FEBase/html/032001.htm
/ABC/efg/Frontend/xml/Transactions/060658.xml       1.2     20071213        SPR 30418       /FEBase/xml/Transactions/060658.xml
/ABC/efg/BANCS-24/cob/CI0051.COB    1.35    20071213        SPR 30417       /BASE/src/CI0051.COB
/ABC/efg/Core/htc/FlowComponents/CommissionFetch.htc        1.5     20071213        SPR 30251       /FEBase/htc/FlowComponents/CommissionFetch.htc


Last edited by zedex; 04-11-2008 at 02:47 PM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0