![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl question regarding [ ] | hankooknara | Shell Programming and Scripting | 2 | 07-01-2007 01:21 PM |
| perl question | BG_JrAdmin | Shell Programming and Scripting | 1 | 09-09-2005 04:46 PM |
| Perl Question | Gary Dunn | Shell Programming and Scripting | 2 | 12-03-2004 09:37 AM |
| PERL question | frank | Shell Programming and Scripting | 1 | 06-18-2002 12:13 AM |
| Perl question | Jubba | Shell Programming and Scripting | 1 | 04-01-2002 11:24 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
PERL question
Hello,
pkzipc of a certain zip file yeilds the following in shell Code:
PKZIP(R) Version 6.0 FAST! Compression Utility for AIX Copyright 1989-2002 PKWARE Inc. All Rights Reserved. Registered Version PKZIP Reg. U.S. Pat. and Tm. Off. Patent No. 5,051,745 Viewing .ZIP: test.zip Length Method Size Ratio Date Time CRC-32 Mode Name ------ ------ ---- ----- ---- ---- ------ ---- ---- 1002KB DeflatN 226KB 77.5% 09/26/2005 3:16p a7f6d4e9 0777 M0511514944/file1 474KB DeflatN 91KB 80.8% 09/26/2005 3:16p fbc1c376 0777 M0511514944/file2 476KB DeflatN 91KB 80.9% 09/26/2005 3:16p 9fac9cf5 0777 M0511514944/file3 113KB DeflatN 92KB 18.5% 09/26/2005 3:16p 5b5b5521 0777 M0511514944/file4 ------ ------ ----- ---- 2065KB 500KB 75.8% 4 issue the following shell command. Code:
pkipc test.zip Code:
PKZIP(R) Version 6.0 FAST! Compression Utility for AIX Copyright 1989-2002 PKWARE Inc. All Rights Reserved. Registered Version PKZIP Reg. U.S. Pat. and Tm. Off. Patent No. 5,051,745 Viewing .ZIP: test.zip Length Method Size Ratio Date Time CRC-32 Mode Name ------ ------ ---- ----- ---- ---- ------ ---- ---- 1002KB DeflatN 226KB 77.5% 09/26/2005 3:16p a7f6d4e9 0777 M0511514944/file1 474KB DeflatN 91KB 80.8% 09/26/2005 3:16p fbc1c376 0777 M0511514944/file2 476KB DeflatN 91KB 80.9% 09/26/2005 3:16p 9fac9cf5 0777 M0511514944/file3 113KB DeflatN 92KB 18.5% 09/26/2005 3:16p 5b5b5521 0777 M0511514944/file4 ------ ------ ----- ---- 2065KB 500KB 75.8% 4 Code:
COMMENT ; Length Method Size Ratio Date Time CRC-32 Mode Name COMMENT ; ------ ------ ---- ----- ---- ---- ------ ---- ---- COMMENT ; 1002KB DeflatN 226KB 77.5% 09/26/2005 3:16p a7f6d4e9 0777 M0511514944/file1 COMMENT ; 474KB DeflatN 91KB 80.8% 09/26/2005 3:16p fbc1c376 0777 M0511514944/file2 COMMENT ; 476KB DeflatN 91KB 80.9% 09/26/2005 3:16p 9fac9cf5 0777 M0511514944/file3 COMMENT ; 113KB DeflatN 92KB 18.5% 09/26/2005 3:16p 5b5b5521 0777 M0511514944/file4 COMMENT ; ------ ------ ----- ---- COMMENT ; 2065KB 500KB 75.8% 4 Please advise me on how to achieve this using PERL. Thanks for your help. Jerardfjay |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
pkipc test.zip |awk '"Length"==$1,0{print "COMMENT ; " $0}' >>logfile
|
|
#3
|
|||
|
|||
|
In Perl, something along the lines of
Code:
#!/usr/bin/perl
$out = `pkzipc test.zip`;
$start = 0;
$buf = '';
foreach $line (split /\n/, $out) {
if ($line =~ /^\s*Length/) { $start = 1; }
if ($start) {
$buf .= ('COMMENT ; ' . $line . "\n");
}
}
open FILE, ">>file.txt" or die "cannot open file for writing";
print FILE $buf;
close FILE;
|
|
#4
|
|||
|
|||
|
Thanks cbkihong,
Its exactly what I was looking for. Although I understand the piece where you concatenate the string "COMMENT ;" to the existing lines after filtering unwanted lines, what is the logic that you are using to filter the lines that start with PKZIP,Copyright and Viewing? The other question that I have is that how can I use a variable that holds the name of the logfile instead of hardcoding the line Code:
open FILE, ">>file.txt" or die "cannot open file for writing"; Jerardfjay Last edited by jerardfjay; 09-28-2005 at 05:19 AM. Reason: claifying the question |
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
|||
|
|||
|
Quote:
But a warning though. The routine will not notice if the command fails for whatever reason. Maybe you will want to check $? (if pkzipc obeys so) for return value, e.g. Code:
$out = `pkzipc test.zip`;
if ($? >> 8) {
# error (assume non-zero return status is error)
}
http://search.cpan.org/~smpeters/Arc...mple_accessors |
|
#7
|
|||
|
|||
|
Quote:
Code:
open FILE, ">>file.txt" or die "cannot open file for writing"; Moreover, there is logic in the original program to perform a pkzipc only when the contents of the zip file is greater than zero. Thanks for your help. Jerardfjay |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|