I have a log file that has this format:
DATE-TIME ### attribute1 ### attribute2 ### attribute3
I need to look for this log file for an input attribute (entered from the command line) and output lines corresponding to the entered attribute.
A naive approach might be something like this:
scan the entire file line by line
search for the attribute
print if found, else ignore.
This approach is slow because it will require O (n) comparisons, where n is the number of rows that can be very large.
Using a hash table may be another approach, but storing such a hash table in memory for a large file may not be possible.
So what is the best possible solution? How can I index the entire file by various attributes?
EDIT:
A log file can be about 100K lines, almost like syslog files on Linux. With one call, the user can search for several attributes that are unknown until the search for the 1st attribute is completed as an interactive console.
Thank,
source
share