searching for lines > 45 days

I have a field in a text file 11:39:16 2007-10-07. Is there anyway to
use grep or a similiar tool to extract all lines over 45 days to
another file and remove them from the original file ?

Thanks,
Pete
Peter [ Di, 08 Januar 2008 00:32 ] [ ID #1902404 ]

Re: searching for lines > 45 days

Peter wrote:
> I have a field in a text file 11:39:16 2007-10-07. Is there anyway to
> use grep or a similiar tool to extract all lines over 45 days to
> another file and remove them from the original file ?
>
> Thanks,
> Pete

With GNU awk (untested):

mv file backup &&
gawk 'BEGIN{ FS="[- :]"; now = systime(); age = 60*60*24*45 }
{ then = mktime($4" "$5" "$6" "$1" "$2" "$3)
print > ((now - then) > age ? "old" : "file")
}' backup &&
rm backup

Obviously you may want to leave "backup" around until you verify the
script does what you want.

Regards,

Ed.
Ed Morton [ Di, 08 Januar 2008 05:25 ] [ ID #1902412 ]

Re: searching for lines > 45 days

On Jan 8, 7:32 am, Peter <petercri... [at] yahoo.com> wrote:
> I have a field in a text file 11:39:16 2007-10-07. Is there anyway to
> use grep or a similiar tool to extract all lines over 45 days to
> another file and remove them from the original file ?
>
> Thanks,
> Pete

#!/bin/sh

t=`echo "11:39:16 2007-10-07" | sed 's/[:-]/ /g'`
set -- $t
string="$4$5$6$1$2"
touch tempfile
touch -t $string tempfile
result=`find . -mtime +45 -ls |grep tempfile > /dev/null`
if [ "$result" -eq 0 ];then
echo "Found line"
rm tempfile
fi
mik3l3374 [ Di, 08 Januar 2008 08:18 ] [ ID #1902417 ]

Re: searching for lines > 45 days

On Jan 7, 5:32 pm, Peter <petercri... [at] yahoo.com> wrote:
> I have a field in a text file 11:39:16 2007-10-07. Is there anyway to
> use grep or a similiar tool to extract all lines over 45 days to
> another file and remove them from the original file ?
>
> Thanks,
> Pete

#!ruby
require 'date'
File.open('old','w'){|old| File.open('new','w'){|new|
ARGF.each{|s|
(Date.today - Date.parse(s[/\d{4}-\d\d-\d\d/]) < 45 ? new : old).
print s
}
}}
William James [ Mi, 09 Januar 2008 00:34 ] [ ID #1903288 ]
Linux » comp.unix.shell » searching for lines > 45 days

Vorheriges Thema: Re: I don't understand why the following increases cpu time
Nächstes Thema: Highlighted Menu