I know how to read a file line by line. But don't to how to skip to a line matching a criteria and then continue reading it till the end.
This is a log file. The input is a timestamp.
Find the timestamp in the log file
Read the remaining lines one at a time till EOF.
How can I do this?
pludi
July 29, 2011, 7:51am
2
sed -ne '/timestamp/,$p' yourfile
1 Like
you mean, p will have the rest of the file and i read it line by line?
pludi
July 29, 2011, 7:59am
4
No. It's a sed script, telling it not to print the contents of the file, until the timestamp is found. From there on to the rest, print the file as it is.
Ok here is my code
while read line
do
processLine
done < $logFile
Now where and how does your statement fit here?
---------- Post updated at 05:49 PM ---------- Previous update was at 05:34 PM ----------
I haven't worked much in unix, so finding it hard to perform simple operations
panyam
July 29, 2011, 8:24am
6
If you want to do some "processing" on lines read after "timestamp" occured,
sed -ne '/'"${timestamp}"'/,$p' yourfile | while read line
do
## do processing
done
1 Like
I am trying use a variable for timestamp like
sed -ne '/$timestamp/,$p' yourfile | while read line
And sed is not matching any records. I tried '$timestamp', "$timestamp"....nothing seems to be working.
---------- Post updated at 06:53 PM ---------- Previous update was at 06:48 PM ----------
I tried
sed -ne '/2011\/06\/28 11\:16\:14/,$p' test.log
on command prompt and it works fine.
panyam
July 29, 2011, 9:24am
8
check my last edited post and see if it works.
nope, it doesn't work. I am really not understanding the usage of single and double quotes.
Can you please provide some pointers to read up?
If my timestamp="11:16:14" then
sed -ne '/'"$timestamp"'/,$p' $logFile
works fine
And if timestamp="2011/06/28 11:16:14"
then nothing works.
Any reasons?
---------- Post updated at 12:35 PM ---------- Previous update was at 09:04 AM ----------
work around
I replaced "/" with "\/" and ":" with "\:" and the above command worked like charm.