get all entries after particular date !!

hi all
i have a file in which first column has date in (yyyy-mm-dd) format and rest of the column has file information.
i want to write a program in such way that when i specify date i will get entries from that date till end of file.and there can be more than one entries for particular date.

in short i want to split file in 2 parts one part will have entries till date i have mentioned ( without date i have mentioned ) and other will have all entries from date i have mentioned till end of file. i am writing code in perl/shell script.

i am not getting how to do this till now..please suggest how this can be done ??

here is my file :

2007-10-18    abcs.sql   1.1  
2007-10-18    adah.sh    1.0
2007-10-18    hhsh.pl     1.9
2007-10-19    hhhh.pl     1.9
2007-10-20    nnnn.sql    1.0
2007-10-20    zzzz.COB   1.147
2007-10-20    rreerf.sh    1.5
2007-10-20    sdigj.sh      1.6
2007-10-21    sdhgfi.sh    1.7
2007-10-21    dghidf.sh    1.8

if i specify 2007-10-19 then i should get all entries from this date till end of file.

Try:

>fecha=2007-10-19

> awk -v valor=${fecha} 'BEGIN {gsub(/-/,"",valor)}
        { 
        h=$1
        gsub(/-/,"",h)
        if ( h >= valor )
                print
}' file
2007-10-19    hhhh.pl     1.9
2007-10-20    nnnn.sql    1.0
2007-10-20    zzzz.COB   1.147
2007-10-20    rreerf.sh    1.5
2007-10-20    sdigj.sh      1.6
2007-10-21    sdhgfi.sh    1.7
2007-10-21    dghidf.sh    1.8

Is the data ordered by date?
If yes (assuming Awk is acceptable):

awk '$1>dt' dt="2007-10-19" filename

If not:

awk 'f;$1==dt{f=1}' dt="2007-10-19" filename

If you want to use split, try the following:

#!/bin/sh

sed -e '1s/2007\-10\-20/XXXX\-10\-20/;t' -e '1,/2007\-10\-20/s//XXXX\-10\-20/'  yourfile > s1
split -p "XXXX-10-20" s1 sout
rm s1
sed '1s/^XXXX/2007/g' soutab

Output is in files soutaa and soutab

thanx got what i wanted used one line awk to do this thanx radoulov

ninad

Hi radoulov,

Can you please explain me wat actually happens here? Wat does 'f' mean here?

awk 'f;$1==dt{f=1}' dt="2007-10-19" filename

Thanks in advance,
Chella

[LEFT]f is a variable, its name is arbitrary (it can be any valid variable name).
In Awk uninitialized variables have the numeric value zero.
When the first filed of the current record matches our pattern ($1==dt),
we set f to 1 (or any other number != 0 - for Awk 0 and null mean false,
all others mean true). We check every record
(first check, then set, so the record that matches
is not printed), we print the records once the variable is set to 1 (true).[/LEFT]

It goes like this:

dt="2007-10-19"

record: 2007-10-18 
code: f 
action: checks f is not 0 -> f==0 (uninitialized yet) -> do nothing
code: $1==dt{f=1}
action: $1!=dt -> do nothing

record: 2007-10-19
code: f
action: checks f is not 0 -> f==0 (uninitialized yet) -> do nothing
code: $1==dt{f=1}
action: $1==dt -> set f to 1(true) --> initialized here!

record: 2007-10-20
code: f
action: checks f is not 0 -> f==1 -> default action: print the current record
code: $1==dt{f=1}
action: $1!=dt -> do nothing (even if $1==dt, we will set again f to 1,
but it doesn't matter :)

Thanks a lot for this radoulov :slight_smile:

Chella