Sponsored Content
Top Forums Shell Programming and Scripting select the lines in between some time span Post 302566498 by birei on Thursday 20th of October 2011 12:45:25 PM
Old 10-20-2011
Hi me_newbie,

A possible solution using 'perl':
Code:
$ cat infile 
---some text---- 01/Jan/2010 ---- some other text ----
---some text---- 10/Jan/2010 ---- some other text ----
---some text---- 20/Dec/2010 ---- some other text ----
---some text---- 01/Jan/2011 ---- some other text ----
---some text---- 02/Jan/2011 ---- some other text ----
$ cat script.pl
use warnings;
use strict;
use POSIX;

my %TAB_MONTH = ( 
        jan     =>      0,
        feb     =>      1,
        mar     =>      2,
        apr     =>      3,
        may     =>      4,
        jun     =>      5,
        jul     =>      6,
        aug     =>      7,
        sep     =>      8,
        oct     =>      9,
        nov     =>      10,
        dec     =>      11
);

die qq[Usage: perl $0 input-file date-from date-to\n] unless @ARGV == 3;

my $utc_date_to = date_str_to_utc( pop @ARGV ) or die qq[Bad format of date (dd/mmm/yyyy)\n];
my $utc_date_from = date_str_to_utc( pop @ARGV ) or die qq[Bad format of date (dd/mmm/yyyy)\n];

while ( <> ) {
        next if m/\A\s*\z/;
        chomp;
        my $utc_date_line = date_str_to_utc( $_ ) or next; 
        if ( $utc_date_line >= $utc_date_from && $utc_date_line <= $utc_date_to ) {
                printf "%s\n", $_;
        }
}


sub date_str_to_utc {
        my ($date_str) = $_[0];

        my ($mday,$month,$year) = $date_str =~ m|\b(\d{2})/(\w{3})/(\d{4})| or return;
        my $utc_date = POSIX::mktime( 0, 0, 0, $mday, $TAB_MONTH{ lc $month }, $year - 1900 );

        return $utc_date;
}
$ perl script.pl infile "09/Jan/2010" "01/Jan/2011"
---some text---- 10/Jan/2010 ---- some other text ----
---some text---- 20/Dec/2010 ---- some other text ----
---some text---- 01/Jan/2011 ---- some other text ----

Regards,
Birei
This User Gave Thanks to birei For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

important. select 10 files each time.

Suppose I have a unix file which contain a lost of 60 files like filename1 filename2 ... .. ... filename60 I want to write a unix script that will pick up first 10 files in first run 10-20 files in 2 run 20-30 files in 3 run 30-40 files in 4 run 40-50 files in 5 run 50-60 files in 6... (2 Replies)
Discussion started by: er_zeeshan05
2 Replies

2. UNIX for Dummies Questions & Answers

Extracting a Time Span from Syslog Messages File

Hi all, I need your help to explain how I can extract a time span from the syslog messages file on a Solaris 10 system. Here is an example extract of the syslog messages: Dec 4 11:51:38 hajap141-0107.nls.jlrint.com 267938: Dec 4 11:51:36: %DOT11-6-DISASSOC: Interface Dot11Radio0,... (4 Replies)
Discussion started by: wthomas
4 Replies

3. Shell Programming and Scripting

Select lines in which column have value greater than some percent of total file lines

i have a file in following format 1 32 3 4 6 4 4 45 1 45 4 61 54 66 4 5 65 51 56 65 1 12 32 85 now here the total number of lines are 8(they vary each time) Now i want to select only those lines in which the values... (6 Replies)
Discussion started by: vaibhavkorde
6 Replies

4. Shell Programming and Scripting

How to select/delete some lines in shell?

I need to delete half(approx) the file or select half the file by existence of some character My file looks like 1 2 3 4 . . . 50 . . 100I need to select only 50 to rest of the file or needs to delete the file upto 50. Please help me out.. (6 Replies)
Discussion started by: SujeethP
6 Replies

5. Shell Programming and Scripting

need to grep contents of a file within specific time span. regex i am using is not working

Hi , I am trying to extract contents of a file between specified time stamp. but it does not seem to work. i am trying to extract output of /var/adm/messages between 15:00:00 to 15:23:59 . i have tried two regex the first one seems to kind of work. it displays some output. the second one is... (13 Replies)
Discussion started by: chidori
13 Replies

6. Shell Programming and Scripting

Select files by time stamp

Hi, I need help to read file in a directory on basis of time stamp. e.g. If file access in last 2 minutes it should not be copy to remote directory. Below is my script. +++++++++++++++++++++++++ #!/bin/ksh DATE=`date +"%Y-%m-%d_%H%M"` SEPARATER=" " exec < out_interfaces.cfg... (1 Reply)
Discussion started by: qamar.alam
1 Replies

7. UNIX for Dummies Questions & Answers

How to randomly select lines from a text file

I have a text file with 1000 lines, I want to randomly select 200 lines from it and print them as output. How do I go about doing that? Thanks! (7 Replies)
Discussion started by: evelibertine
7 Replies

8. Shell Programming and Scripting

Select lines where at least x columns above threshold value

I have a file with 20 columns. I'd like to retain only the lines for which the values in at least x columns, looking only at columns 6-20, are above a threshold. For example, I'd like to retain only the lines in the file below that have at least 8 columns (again, looking only at columns 6-20)... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

9. Shell Programming and Scripting

Combine logs span across multiple lines

Hi All, I am having a log file ERROR 2016-12-08 10:22:23.542 some data **** some data****** **** some data****** **** some data****** DEBUG 2016-12-08 10:23:23.542 some data **** some data****** **** some data****** **** some data****** when i grep the log file with ERROR am getting... (3 Replies)
Discussion started by: mohanalakshmi
3 Replies

10. UNIX for Beginners Questions & Answers

Total size utilizes by the files older than a time span

Through find command I identified the files older that 1 year. I need the overall size utilizes by these 1 year older files. Please share me the command to identify it .Thanks Please post in an adequate technical forum! (3 Replies)
Discussion started by: Sang
3 Replies
curs_scroll(3CURSES)					     Curses Library Functions					      curs_scroll(3CURSES)

NAME
curs_scroll, scroll, scrl, wscrl - scroll a curses window SYNOPSIS
cc [ flag ... ] file ... -lcurses [ library ... ] #include <curses.h> int scroll(WINDOW *win); int scrl(int n); int wscrl(WINDOW *win, int n); DESCRIPTION
With the scroll() routine, the window is scrolled up one line. This involves moving the lines in the window data structure. As an optimiza- tion, if the scrolling region of the window is the entire screen, the physical screen is scrolled at the same time. With the scrl() and wscrl() routines, for positive n scroll the window up n lines (line i+n becomes i); otherwise scroll the window down n lines. This involves moving the lines in the window character image structure. The current cursor position is not changed. For these functions to work, scrolling must be enabled via scrollok(). RETURN VALUES
All routines return the integer ERR upon failure and an integer value other than ERR upon successful completion. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
curs_outopts(3CURSES), curses(3CURSES), attributes(5) NOTES
The header <curses.h> automatically includes the headers <stdio.h> and <unctrl.h>. Note that scrl() and scroll() may be macros. SunOS 5.10 31 Dec 1996 curs_scroll(3CURSES)
All times are GMT -4. The time now is 06:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy