Perl code to extract data from the range of date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl code to extract data from the range of date
# 1  
Old 06-11-2009
Perl code to extract data from the range of date

Hi All,

I'm still a newbie in perl programming. I have a data below say in test.tmp

The output in test.tmp will be the same data as above sample in test.tmp . So after i get all the 4th column data within the range of month and year i need, then i will use the foreach () code to execute another command to get the job done Smilie

Thanks in advance for your help Smilie

Last edited by miskin; 06-16-2009 at 10:22 AM..
# 2  
Old 06-11-2009
Hammer & Screwdriver

#build a month hash
my %month_hash = ( 'jan' => 1, 'feb' => 2, 'mar' => 3, ... ,'dec' => 12);

while (my $line = <FH>){
chomp $line;
my @cols = split (' ',$line);
#mon date year id
if ($cols[2] >= $from_year && $cols[2] <= $to_year && $month_hash{lc($cols[0])} >= $month_hash{lc($from_month)} && $month_hash{lc($cols[0])} <= $month_hash{lc($to_month)} ) {
print "$cols[3]\n";
}
}



Note: There are many scripting lang which produces the desired result . the key is what you want to use and the ability to try and use it. if you give up you will end up being a newbie.

Cheers,
fellow newbie Image
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract repetead values in date range

Gents, Using the following values: 3687650458 08/29/2017 1.67581 3687650388 08/29/2017 1.67581 3687650330 08/29/2017 1.67581 3687650330 08/29/2017 1.67581 3687650330 08/28/2017 2.67581 3687650330 08/28/2017 2.67581 3687650330 08/27/2017 3.67581 3687650330 08/27/2017 3.67581 3687650330... (6 Replies)
Discussion started by: jiam912
6 Replies

2. Shell Programming and Scripting

Extract data from log file in specified range of time

I was searching for parsing a log file and found what I need in this link http://stackoverflow.com/questions/7575267/extract-data-from-log-file-in-specified-range-of-time But the most useful answer (posted by @Kent): # this variable you could customize, important is convert to seconds. # e.g... (2 Replies)
Discussion started by: kingk110
2 Replies

3. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

4. Shell Programming and Scripting

How to extract information from two files with data range

Hi, I want to make a query about extracting data from two files that both have data ranges. the data that i want to extract; when there is matching between file1 column 2 is equal to file2 column2 , and file1 column 3 and column 4 is within the range of file2 columns 3 and 4. I would like rows... (1 Reply)
Discussion started by: houkto
1 Replies

5. Shell Programming and Scripting

Search for a specific data in a file based on a date range

Hi, Currently I am working on a script to automate the process of converting the log file from binary into text format. To achieve this, partly I am depending on my application’s utility for this conversion and the rest I am relying on shell commands to search for directory, locate the file and... (5 Replies)
Discussion started by: svajhala
5 Replies

6. Shell Programming and Scripting

How to put date range from a perl & sql script

Hi Guys, Can someone please help me on adding/inserting a variable date to an sql scipt? Basically I want to assign a 7 days date range. As shown below.. #!/usr/bin/perl use strict; use Env qw(ORACLE_HOME); my $SQLPLUS='/opt/oracle/product/10.1.0/db_1/bin/sqlplus -S... (1 Reply)
Discussion started by: pinpe
1 Replies

7. Shell Programming and Scripting

Get Data Between a specific Date Range from logs

I need to extract data from logs for a mentioned date range..Its quite urgent can anyone help me out with it..its to be written in unix..just thought its better to specify.. (4 Replies)
Discussion started by: sankasu
4 Replies
Login or Register to Ask a Question