greping date in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting greping date in a file
# 1  
Old 02-20-2008
greping date in a file

i have a script that checks inside the file and find the start date and end date with time...........

#!/bin/ksh

cd /ednadtu3/u01/pipe/logs

TZ=`date +%Z`+24 ;b=`date +%Y-%m-%d`
echo $b

for i in DBMaint.log
do
echo "Start Time:" >> /ednadtu3/u01/pipe/naveed/Report.txt
cat $i | grep $b | while read LINE1
do
echo $b >> /ednadtu3/u01/pipe/naveed/Report.txt
done

echo "End Time:" >> /ednadtu3/u01/pipe/naveed/Report.txt
cat $i | grep $b | while read LINE2
do
echo $b >> /ednadtu3/u01/pipe/naveed/Report.txt
done
done
------------------------------------------------------------------

this script is returning null result..... i know something is wrong in the logic.

actually i want to cat a file and check the start time of the file and end time of the file........

can anyone help me in that
# 2  
Old 02-20-2008
Does DBMaint.log have timestamp on each line ?
In that case you can simply take the first and last line on that file and cut the date part accordingly.
# 3  
Old 02-20-2008
here is the format of the file

2008-02-18 20:43:17,965 [Thread-14] DEBUG - SummaryReport.sendStatistics(): Statistics Serialized Message Size: 1804

2008-02-19 21:43:17,967 [Thread-14] DEBUG - SummaryReport.sendStatistics(): Statistics Serialized Message Size: 1804

2008-02-19 22:43:17,968 [Thread-14] DEBUG - SummaryReport.sendStatistics(): Statistics Serialized Message Size: 1809

2008-02-19 23:43:17,969 [Thread-14] DEBUG - SummaryReport.sendStatistics(): Statistics Serialized Message Size: 1808

2008-02-19 23:23:17,970 [Thread-14] DEBUG - SummaryReport.sendStatistics(): Statistics Serialized Message Size: 1800

2008-02-20 13:43:17,971 [Thread-14] DEBUG - SummaryReport.sendStatistics(): Statistics Serialized Message Size: 1805
-----------------------------------------------------------------------

how to find the last line and 1st line in the file having this format.it contains some 1000 of lines like this. i m just interested in 2008-02-19 date. in this date how to find 1st and last line
# 4  
Old 02-20-2008
i have got the script for start time and end time.

----------------------------------------------------------------------

#!/bin/ksh

if test -f Report.txt
then
rm Report.txt
fi

cd /ednadtu3/u01/pipe/logs

TZ=`date +%Z`+24 ;b=`date +%Y-%m-%d`
echo $b

for i in DBMaint.log
do
echo "Start Time:" >> /ednadtu3/u01/pipe/naveed/Report.txt
cat $i | grep $b | head -1 >> /ednadtu3/u01/pipe/naveed/Report.txt

echo "End Time:" >> /ednadtu3/u01/pipe/naveed/Report.txt
cat $i | grep $b | tail -1 >> /ednadtu3/u01/pipe/naveed/Report.txt
done

-----------------------------------------------------------------------

the o/p is :

Start Time:
2008-02-19 00:13:16,338 [Thread-14] INFO -

End Time:
2008-02-19 23:43:17,974 [Thread-14] DEBUG - SummaryReport.sendStatistics(): Statistics Serialized Message Size: 1807

---------------------------------------------------------------------

How to find the diff in time ..........

Last edited by ali560045; 02-20-2008 at 07:44 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Greping frequency for list of phrases is a separate file

Dear All I have a big set of data which I would like to summerize to have a better sense of it the problem is like this ... I have more than 200 files each related to a person which includes different sentences with specific elements (files in a directory) e.g. mark (one file in the directory)... (9 Replies)
Discussion started by: A-V
9 Replies

2. Shell Programming and Scripting

Partial content greping into a 3rd file

Hi, I do have couple of files in folder. The names of each of the files have a pattern. B_A17_A17_1T.txt B_A17_A17_2T.txt B_A17_A17_3T.txt B_A17_A17_7T.txt ..... ..... B_A17_A17_45T.txt Each of the above files have the same pattern of data with 4 columns and have an header for... (10 Replies)
Discussion started by: Kanja
10 Replies

3. UNIX for Dummies Questions & Answers

How to pick the latest file with date as one among the file name.( not exactly present date.)?

i have files like 1)20131112_abc_01.csv and 2)20131113_abc_01.csv and 3)20131113_abc_02.csv when i try to fetch the file in the next day. it shud pick the third file.. plz help me.. and i use `date +"%Y%m%d"` command to fetch..it fetches the current date... (2 Replies)
Discussion started by: applepie
2 Replies

4. Shell Programming and Scripting

Greping values from a text file

Hi All, I have 100's of files in the following format. I need to grep or parse out some values from each of the files {  “tree”: “((A:0.2{0},B:0.09{1}):0.7{2},C:0.5{3}){​4};”,  “placements”:  , ], “n”: },   {“p”: ], “n”: } ],  “metadata”:  {“invocation”:   “pplacer -c... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

5. Shell Programming and Scripting

Need Help with greping two line from a file Pls help ASAP

Hi all - I''m in a little bit of jam - If you can please help I have a file that has the following content ( please see below) I need to read the file and then get this result in this format ------------- To put out in this format name: sophis Total: 22328 name: tca ... (2 Replies)
Discussion started by: mnassiri
2 Replies

6. Shell Programming and Scripting

need help in greping

Hi, i have to find a string in a file and positin of the string in the file would come in some particular interval. let's say file is 1-1000 lines and string is in from 200-300line. could any one suggest me how to get make the grep search for the string in that particular portion of the... (4 Replies)
Discussion started by: tarakant
4 Replies

7. Shell Programming and Scripting

Greping columns data from file.

Hi i am using shell script which perform oracle database query and after that output is redirect to some temporary file. the output of this file looks like SQL*Plus: Release 10.2.0.2.0 - Production on Tue Aug 5 16:08:06 2008 Copyright (c) 1982, 2005, Oracle. All Rights Reserved. ... (6 Replies)
Discussion started by: esungoe
6 Replies

8. Shell Programming and Scripting

problem in greping the string from file using awk

I am using awk command for greping an value from the file the file contains .. file ---------------------------- content----------- -------- String main = "81507066666"; ------------------------------ i am greping the above value using awk command NumberToReplace=`cat "file" | grep... (1 Reply)
Discussion started by: vastare
1 Replies

9. Shell Programming and Scripting

need help in greping

i have a ksh script : #!/bin/ksh TZ=`date +%Z`+24 ;a=`date +%Y-%m-%d` b=`date +"%H:%M:%S"` cd /ednadtu3/u01/pipe/logs for i in Archiver1.log do cat $i | grep $a | grep $b >> /ednadtu3/u01/pipe/naveed/Insert_Date.txt done... (4 Replies)
Discussion started by: ali560045
4 Replies

10. Shell Programming and Scripting

greping certain modified date

i have a k shell script that grep less than certain modified date ------------------------------------------------- #!/bin/ksh for i in * do day=`ls -ltr | grep $i | tr -s " " | cut -d " " -f6-7 | awk 'substr($0,7,4)substr($0,1,5)substr($0,11)<"Feb 1"' ` echo $day done... (2 Replies)
Discussion started by: ali560045
2 Replies
Login or Register to Ask a Question