By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

extract a log file to filter previous dates

P: 7
Hi,

I have problem of filtering a log file from my perl script.

This is the file content of the file pinpe.csv:

2009-06-16
2009-01-29
2009-06-02
2008-03-05
2007-08-05


Here is my perl code.
Expand|Select|Wrap|Line Numbers
  1. use Net::Telnet;
  2.  
  3. @DATE=$telnet->cmd("date '+%Y-%m-%d'");
  4. chomp($DATE[0]);
  5.  
  6. @Discon=$telnet->cmd("cat /data/pinpe.csv | nawk '{print \$4}' | perl -ne 'print if \$_ lt $DATE[0]'");
  7. chomp($Discon[0]); 
  8.  
  9. print "@Discon[0]\n";
and this is the output error:
Expand|Select|Wrap|Line Numbers
  1. Illegal octal digit '8' at -e line 1, at end of line
Now my dilemma is I want to filter this ouput by my preferred dates. I wanted it to output the date from yesterday and backwards. In other words I want to filter all the dates less than today's date (i.e. 2007-07-30, 2007-07-29, 2007-07-28, etc. and below).

Tnx in advance. :)

Was it perl thought that I was dealing with an octal number and when he came along with 8 which stopped it from making sense, so perl quite rightly complained? Pls help. Tnx.

Br,
Pete
Aug 2 '07 #1
Share this Question
Share on Google+
5 Replies


KevinADC
Expert 2.5K+
P: 4,059
hmmm, looks familiar.
Aug 2 '07 #2

P: 7
hmmm, looks familiar.
Hi KevinADC,

Are you the same person from perlguru.com? Anyway I'm still looking around for someone who can help me most.

Br, Pete
Aug 2 '07 #3

KevinADC
Expert 2.5K+
P: 4,059
Yes, that is me.
Aug 3 '07 #4

P: 7
Hi,

Someone solved my problem on perlmonks.

I just want to share it with you guys. Below is the right syntax for my code.

Expand|Select|Wrap|Line Numbers
  1. use Net::Telnet;
  2. use IPadd;
  3.  
  4. $ipadd=IPadd->new();
  5. $ipadd->ipadd1();
  6.  
  7. @Date1=$telnet->cmd("date '+%Y%m%d'");
  8. chomp($Date1[0]);
  9. @Date2=$telnet->cmd("date '+%Y-%m-%d'");
  10. chomp($Date2[0]);
  11.  
  12. @Discon=$telnet->cmd("cat /data/pinpe.csv_@Date1[0] | nawk -v FS=, '{print \$1','\$18','\$22','\$26}' | grep -w $array1[$count-1] | grep -w 1 | nawk '{print \$4}' | perl -ne 'print if \$_ lt \"@Date2[0]\"' | wc -l");
The key to my problem is 'interpolation'. The code that the Perl interpreter sees is:

Expand|Select|Wrap|Line Numbers
  1. print 2007-08-05;
  2.  
which is some arithmetic (2007 - 08 - 05) containing two octal constants and a decimal constant. The proper syntax is I need to quote the interpolated date so that the interpreter sees a string instead:

Expand|Select|Wrap|Line Numbers
  1. \"@Date2[0]\"
  2.  
Cheers! :)

Br, Pete
Aug 3 '07 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
Thanks for sharing! Glad you solved your issue!

Regards,

Jeff
Aug 3 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.