Performing a while for two files


 
Thread Tools Search this Thread
Top Forums Programming Performing a while for two files
# 8  
Old 06-17-2013
Is that syntax okay for perl?
# 9  
Old 06-17-2013
No that's shell.
And IMHO you want to read the log files in sequence.
# 10  
Old 06-17-2013
yes, first today's one and then previous day.
# 11  
Old 06-18-2013
Code:
#! /usr/bin/perl -w

use strict;
use POSIX 'strftime';

# Grab yesterday's date in $yest_date
my $yest_date = strftime("%Y%m%d", localtime(time - 86400));
# Glob yesterday's filename in $yest_file
my $yest_file = glob "access.${yest_date}-*";
my $line = undef;

# Iterate through today's and yesterday's file (in the same sequence).
for ("access", $yest_file) {
    # Open the file in consideration
    open FH, "< $_";
    
    # Read the file content line by line using while loop
    while ($line = <FH>) {
        <statements>
    }
    
    # Close the filehandle.
    close FH;
}

# 12  
Old 06-18-2013
Thank you for your response.

How do I run the command, either one gives me an error :

Code:
perl mfile.pl

Code:
perl mfile.pl access

Code:
readline() on unopened filehandle statements at mfile.pl line 19.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk: Performing "for" loop within text block with two files

I am hoping to pull multiple strings from one file and use them to search within a block of text within another file. File 1PS001,001 HLK PS002,004 MWQ PS004,002 RXM PS004,006 DBX PS004,006 SBR PS005,007 ML PS005,009 DBR PS005,011 MR PS005,012 SBR PS006,003 RXM PS006,003 >SJ PS006,010... (11 Replies)
Discussion started by: jvoot
11 Replies

2. Solaris

Solaris not booting with new BE after performing Liveupgrade.

After getting the new BE created and activating the new BE with luactivate command, OS is still booting with OLD BE. Steps followed below.. bash-3.2# bash-3.2# lustatus Boot Environment Is Active Active Can Copy Name Complete Now On Reboot... (3 Replies)
Discussion started by: Kumar07
3 Replies

3. Shell Programming and Scripting

Performing aggregation in File

Hi, I need help in UNIX shell script to handle the following: I have file called File1.txt which contains data something like below: LibraryName|BookName|Flag-Indicator|COUNT LIB1|BOOK1|A|12 LIB1|BOOK1|A|2 LIB2|BOOK2|I|1 LIB2|BOOK1|I|4 LIB1|BOOK2|A|12 LIB1|BOOK1|I|22... (3 Replies)
Discussion started by: vfrg
3 Replies

4. UNIX for Advanced & Expert Users

slow performing system

Friends Greetings. I have a RedHat 5.7 64bit virtual server on VMware ESXi 4.1. This server and other Redhat Servers are running very slow. I did some stats collection on ESXi and looks like Linux is holding the disk IO. I am not sure what is causing this behavior. On Linux I checked the CPU... (4 Replies)
Discussion started by: sdewal
4 Replies

5. Shell Programming and Scripting

Performing lookup quickly

Hello, Have been trying to develop a script that reads a string from an input file then looks up that string in a reference file to get a number, then inset that number back into the original file at a certain point (_____): Input File: HARRY JON _____ AA M N PETER PIE ... (8 Replies)
Discussion started by: dendright
8 Replies

6. UNIX for Dummies Questions & Answers

Performing Batch ftp without .netrc

How can I supply the userID/password when executing FTP in the batch mode? Using .netrc is not an option (prohibited per Corporate Policy). Thank you in advance. (1 Reply)
Discussion started by: compaamat
1 Replies

7. Shell Programming and Scripting

taking count of log files and den performing some actions

hi, I've some log files in a path /SYSTEM/custom/data/MNP/xmlerror as: MNP_PORT_IN_P200902191347563283_20090220181630_err_1.xml MNP_PORT_IN_P200902171717114365_20090220211814_err_2.xml MNP_PORT_IN_P200902191349023233_20090220181923_err_1.xml... (4 Replies)
Discussion started by: ss_ss
4 Replies

8. UNIX for Advanced & Expert Users

Performing Script on Multiple Files

Dear All I have group of files named : CDR.1,CDR.2.,CDR.3,CDR.4,CDR.5,CDR.6,etc....... I am performing an awk command look like this : nawk -f script CDR.* What i want is that i want to perform this command on range of files not all of them. Instead of writing CDR.* i want to write... (3 Replies)
Discussion started by: zanetti321
3 Replies

9. Programming

performing a task at regular intervals

hi! i m tryin to write a program that will perform a specific tasks after fixed interval of time.say every 1 min. i jus donno how to go abt it.. which functions to use and so on... i wud like to add that i am dont want to use crontab over here. ny lead is appreciated. thanx. (2 Replies)
Discussion started by: mridula
2 Replies

10. UNIX for Dummies Questions & Answers

What are core files and how can I delete them when am performing system maintenance??

Help me How can I go about doing this. also, if you have any idea of other files I can delete and what I can do to improve the performance of a system thats running too slow (6 Replies)
Discussion started by: IMPORTANT
6 Replies
Login or Register to Ask a Question