It is currently Tue, 17 May 2022 01:31:57 GMT

Author Message
 Extracting text from a file
I am trying to write a script to extract errors if any from a log file on a
daily basis. So far I can find the date in the file by using:

C_DATE=`date +"%a %b %e "`

and then sed to copy the file to a temp file using

sed -n "/^$C_DATE/,$ p" alert.log > tempfile

However this copies the whole file over to tempfile. What I want to do is
just copy everything from that point down in the file to tempfile. So in the
log extract below I would copy everything from 'Wed Apr 23 13:25:01 2003' to
Wed Apr 23 13:25:01 2003
ARC1: Evaluating archive   log 1 thread 1 sequence 19357
ARC1: Beginning to archive log 1 thread 1 sequence 19357
Creating archive destination LOG_ARCHIVE_DEST_1:
ARC1: Completed archiving  log 1 thread 1 sequence 19357
Wed Apr 23 14:29:45 2003
ORA-000060: Deadlock detected. More info in file
Wed Apr 23 14:29:50 2003

What I do next is extract the ORA- erorrs to another file using

sed -n '/^ORA-/ p' tempfile > ora_errors

and then email it to me. Can anyone tell me how to cut text from a
particular point in a file or suggest a better way of doing what I am trying
to achieve

Thanks for any help

 Sat, 04 Feb 2006 17:27:40 GMT   
 Extracting text from a file

Tyr this:



C_DATE=`date +"%a %b %e "`

fromln=$(grep -n "$C_DATE" $alertlog | head -1 |awk -F: '{print $1;}')

sed -n "${fromln},\$p" $alertlog | grep '^ORA-' >  ORAErrFile

Posted via

 Sat, 04 Feb 2006 22:48:17 GMT   
 Extracting text from a file

Cool stuff. The way I read the OP, I think he may have wanted to save all of
the daily information as well just the ORA stuff. Just in case, I think
using this as the last line should save both:

sed -n "${fromln},\$p" $alertlog | tee DAILYlog | grep '^ORA-' > ORAErrFile

 Sun, 05 Feb 2006 02:58:01 GMT   
 Extracting text from a file
Thanks to both - it is what I needed

 Tue, 07 Feb 2006 20:39:27 GMT   
   [ 4 post ] 

Similar Threads

1. Question: Extracting text from a file.

2. extract text from log file

3. Extracting text from a file in a shell script

4. Question on Extracting Text From Postscript Files

5. Extracting lines from a text file that match a certain criteria to another text file

6. Script to extract portions of text from a text file

7. Postscript file corrupted - extracting text/patching

8. How to extract columns from a text file?

9. Extract specific text from file using sed

10. Extract Records from a text file

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software