|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Jan 8, 7:32 am, Peter <petercri...@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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Jan 7, 5:32 pm, Peter <petercri...@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 } }} |
|
![]() |
| Outils de la discussion | |
|
|