Read text file from a specified string to the end

Hi All,

I like to read the log file from specific time to end of the file.

eg:
message
date and time
message 1
date and time1
message 2
EOF

I want to read all the text (Messages) after date and time to end of the file.
Please let me know the UNIX command to perform this?.

Thanks,
bsraj.

awk

awk '/date and time/{f=1}f' file

shell

while read line
do
 case $line in
 "date and time" ) f=1;; 
 esac
 if [ $f -eq 1 ];then
   echo "$line"
 fi
done < "file"

Hi,

Thanks for your response.
I tried to using the shell script, but i am getting error because there are spaces in between the data and time.
Can we able to get all the lines from the logfile after this string "2008 01 01 12:00:00"?.

Thanks,
bsraj

show how your code.

Hi,

Please find my sample code..

#! /bin/ksh
set -x

LogFile="/tmp/scan_log.log"
LoadFile="/tmp/new_scan_log.log"
Last_Alert="Alert: Fri Jan 4 16:15:01 2008"

while read line
do
case $line in
"$Last_Alert" ) f=1;;
esac
if [ $f -eq 1 ]; then
echo "$line" >> $LoadFile
fi
done < "$LogFile"

Thanks,
bsraj

what's your result with awk version?

Hi,

I am getting the following errors when i tried with the awk command.

awk: syntax error near line 1
awk: bailing out near line 1

show your awk code

I think you need to quote $line:

case "$line" in...

I'm also guessing you need to use a variable in awk:

Last_Alert="Alert: Fri Jan 4 16:15:01 2008"
awk "/$Last_Alert/{f=1}f" file
awk '/'"$Last_Alert"'/{f=1}f' file

Hi,

Thanks for all the details. Yes i am able to get the list from the specified string, but I am not sure how to get the details after the specified string.
EG:
Thu Jan 10 12:56:50 2008
err1
Thu Jan 10 12:56:51 2008
err2

If the specified string = Thu Jan 10 12:56:50 2008 then i like to list all the messages after that string.
Like,
Thu Jan 10 12:56:51 2008
err2

Thanks,
bsraj.