Look back file days in PERL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Look back file days in PERL
# 1  
Old 11-03-2011
Look back file days in PERL

I have 3 variables , $file =abc_2011_11_01.txt (current day file), $back = Yes and $forward = No
I need to search for 3 days back files / 3 days forward files if my current file is not present
logic is,
I need to download the current day file.
If it is missing, i need to look out for currentday -1 file. (abc_2011_10_31.txt )
If that is missint, i need to check for currentday -2 file (abc_2011_10_31.txt )
If $forward is Yes , then I need to look out for currentday +1 file (abc_2011_11_02.txt )
If that is missing, I need to look out for currentday +2 file (abc_2011_11_03.txt )
IMP : The number of days file to check keeps changing. Eg: it may be 3, 4 or 9 etc...
Also, i need to check every file thrice with a sleep time of 100 seconds

How can i achieve this forward/backward check of files in perl?
Thanks in advance
# 2  
Old 11-03-2011
Anything you tried yourself?
# 3  
Old 11-03-2011
yes. Previously I had to check for 3 days back file alone and not forward days check.

Actually I had to create the file name for current date since it wont be available already.
So I used ADD_delta_days function to create the filename as "abc_2011_11_02.txt" and kept the 3 days back files in an array so that i could check one by one.

Now that i need to do both look back and look forward after creating the current day file, am looking out for option other than add_delta_days.
Can you please let me know if its possible
# 4  
Old 11-03-2011
Ok, do you mind posting your code (using code tags) so people can try to see where the problem is?
# 5  
Old 11-03-2011
yes i can post it. but sorry I dont find how to use code tags. Can you please show me the same

---------- Post updated at 02:26 AM ---------- Previous update was at 02:13 AM ----------

Code:
 
code:

my $maxdval = 0-$days_back;
my $d;
for($d=0; $d>=$maxdval; $d--)
{
my $file_name_1 = $base_file_name;
my($yy, $mm,$dd) = Add_Delta_Days(substr($run_dt,0,4), substr($run_dt,4,2), substr($run_dt,6,2), $d);
if($yy < 10  &&  length($yy) < 2) { $yy = "0". $yy };
if($mm < 10  &&  length($mm) < 2) { $mm = "0". $mm };
if($dd < 10  &&  length($dd) < 2) { $dd = "0". $dd };
my $yyyy = $yy;
my $yyyymmdd_1 = $yyyy . $mm . $dd;
$file_name_1 =~ s/yyyymmdd/$yyyymmdd_1/;
push(@fl_nm, $file_name_1);
}

In the above case, the filename is constant pattern - abc_yyyymmdd.
But the one for which am doing, the filename can be any pattern which is not known
Eg: abc_yyyy_mm_dd, abc_YYMMD, abc_mm_dd

---------- Post updated at 03:30 AM ---------- Previous update was at 02:26 AM ----------

Also, Since the file name can be of any format, looking back/forward for files is a constraint when using Add_Delta_days
Can you please suggest alternate way to achieve this
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux froze and got back working 5 days later, no reboot.

Hello my friends, I've come across the weirdest of glitches. I'm running a simple weather monitor (just temperature) on a Raspbeery Pi 3B (Raspbian Linux 4.14.98-v7+). It has a 3G modem that sends out simple packets to my server at home. On june 5th I lost remote access to the device.... (1 Reply)
Discussion started by: OmahaWiz
1 Replies

2. Shell Programming and Scripting

Please help me days to a date string in PERL

Please help me n days to a date string in PERL. Date is of the format YYYYMMDD ---------- Post updated at 08:56 AM ---------- Previous update was at 08:54 AM ---------- Add n days (2 Replies)
Discussion started by: yahoo
2 Replies

3. Shell Programming and Scripting

days difference perl

Hi I have the following issue. the headeer in the file contains as follows IMAHDR tsmdsl01 EMBS_DAT 20120911 20120911 233656S000000000000000 001 So the fifth field in the header is a string that represents the file arrival date.(20120911) yyyyMMDD I just need to compare... (1 Reply)
Discussion started by: ptappeta
1 Replies

4. Shell Programming and Scripting

display all dates 200 days back

i need help! can someone help me please? i try to calculate date under unix (ksh)...AIX operating system. I have to find the date 200 days from today's date. then the script should loop 200 times and display on command line every day's date until the current date. example: todays date:... (4 Replies)
Discussion started by: pavan_test
4 Replies

5. UNIX for Dummies Questions & Answers

display all dates 200 days back

i need help! can someone help me please? i try to calculate date under unix (ksh)...AIX operating system. I have to find the date 200 days from today's date. then the script should loop 200 times and display on command line every day's date until the current date. example: todays date:... (1 Reply)
Discussion started by: pavan_test
1 Replies

6. UNIX for Advanced & Expert Users

back in the good old 7.07 ghostscript days...

back in the good old 7.07 ghostscript days... we had Great results converting pdf to ps output, from the following command: cat $stuff | /usr/local/bin/gs -sDEVICE=ljet4 -q -dNOPAUSE -r200 -sPAPERSIZE=letter -dPDFFitPage -dBATCH -sOutputFile=- - 2> /dev/null | /usr/bin/lp -d $printer ... (3 Replies)
Discussion started by: mr_manny
3 Replies

7. UNIX for Dummies Questions & Answers

Date& Time change in linux beyond few days back

Hi, Could you please let me know the command to change my date /time beyond few days back. Currently when i am trying the below commands able to go beyond one day at max. -->date -->Mon Sep 29 19:31:58 EST 2008 -->export TZ=TMP40:00:00 (Changing the date beyond 40 hours) -->Sun Sep 28... (4 Replies)
Discussion started by: komala
4 Replies

8. Shell Programming and Scripting

Perl: Opening a filehandle but not getting anything back from it

I have two perl functions defined, both run a set of shell commands on some somplied data and return hashs of the resulting parsed output from these shell commands. One works, one doesn't and I can't seem to see why. It's driving me insane :mad: The working one: sub getcellstatus { ... (8 Replies)
Discussion started by: Smiling Dragon
8 Replies

9. Shell Programming and Scripting

Perl: Getting back reference from s modifier

My input text has the following pattens: func_a(3, 4, 5); I want to replace it with this: func_b(3, 4, 5, 6); I'm trying the following expression, but it does not work: perl -p -e "s/func_a\((.*)?\);/func_b(\1,\n6)/s" <... (8 Replies)
Discussion started by: cooldude
8 Replies
Login or Register to Ask a Question