I have a log file which has a format of this kind:
DATE-TIME ### attribute1 ### attribute2 ###attribute3
I have to search this log file for a input attribute(entered from command line) and output the lines that match the entered attribute.
A naive approach may be something like this:
scan the entire file line by line search for the attribute print if found, else ignore.
This approach is slow as it would require O(n) comparisons, where n is number of lines which may be very large.
Another approach may be to use a hash-table but keeping such a in-memory hash-table for a big file may not be possible.
So, what is the best feasible solution? How can I possibly index the entire file on various attributes?
EDIT:
The log file may be about 100K lines, almost like the system log files on linux.
On One invocation, a user may search for multiple attributes, which is not known until the search on 1st attribute is completed like an interactive console.
Thanks,
grep
, or a terrible case of the NIH syndrome.