The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Reading files in directory Dastard Shell Programming and Scripting 3 09-04-2007 03:02 AM
Reading Files oop UNIX for Dummies Questions & Answers 3 07-31-2007 07:40 AM
reading .bin files eastcoast_uix UNIX for Dummies Questions & Answers 1 06-26-2007 01:43 PM
Reading *.chm files? riwa UNIX for Dummies Questions & Answers 3 04-02-2006 09:30 PM
Reading files on different platforms BigTool4u2 Linux 2 04-18-2004 05:47 AM

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

Join Date: Dec 2006
Posts: 31
reading gz files

Hi,
I have a simple perl script where I am passing array of gziped files to the while loop and trying to read content of each field one line at the time using gzcat. Yet, I can not get it to work
Here is what I am doing

...
while ($filename=shift) {

open(MYFILE, "| gzcat $filename");

while ($next=<MYFILE>) {

print $next;

}

}
...
my problem is the
print $next;
never executes.
Somehow inner loop condition returns false even though gz file exist and it is not empty.
I am relatively new to perl and perhaps I am doing something wrong.
Any ideas?
  #2 (permalink)  
Old 02-16-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by arushunter
Hi,
I have a simple perl script where I am passing array of gziped files to the while loop and trying to read content of each field one line at the time using gzcat. Yet, I can not get it to work
Here is what I am doing

...
while ($filename=shift) {

open(MYFILE, "| gzcat $filename");

while ($next=<MYFILE>) {

print $next;

}

}
...
my problem is the
print $next;
never executes.
Somehow inner loop condition returns false even though gz file exist and it is not empty.
I am relatively new to perl and perhaps I am doing something wrong.
Any ideas?
Using Korn Shell:

#!/usr/bin/ksh

while [ -f ${1} ]
do
gzcat ${1}
shift
done
  #3 (permalink)  
Old 02-16-2007
arushunter arushunter is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 31
Found it,
Actually it should be this way

...
open(MYFILE, "gzcat $filename |");
...
Closed Thread

Bookmarks

Tags
perl, perl shift, shift, shift perl

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 10:12 PM.


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