Question : to sort log files by date

Hi, I have logs files like this


2008-10-07 07:44:14,106 INFO [org.springframework.core.CollectionFactory] -

I need to search all the lines for a particular date and then copy them to a different file. For example if I mention Oct 7, 2008 as input the above two lines are to be copied into a new file named  date_file.txt

Thanks in advance,

Answer : to sort log files by date

OK, here's a script which will accept input in YYYY-MM-DD format
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
#!/bin/sh
DATE1=$1
year=`echo $DATE1 | cut -f1 -d-`
mon=`echo $DATE1 | cut -f2 -d-`
day=`echo $DATE1 | cut -f3 -d- | sed "s/^0//"`
 
case $mon in
1)  mon=Jan ;;
2)  mon=Feb ;;
3)  mon=Mar ;;
4)  mon=Apr ;;
5)  mon=May ;;
6)  mon=Jun ;;
7)  mon=Jul ;;
8)  mon=Aug ;;
9)  mon=Sep ;;
10) mon=Oct ;;
11) mon=Nov ;;
12) mon=Dec ;;
esac
 
DATE2="$mon $day, $year"
egrep "$DATE1|$DATE2" /some/log >date_file.txt
Open in New Window Select All
Random Solutions  
 
programming4us programming4us