I'm trying to grep a log file to only show lines that match a certain session ID. Thus far, it works great. However, when I get the results of my grep command, I'm not getting the entries in the order they appear.
If the log file in the directory has this data:
SESSNUM=4437 login.jsp
SESSNUM=4437 welcome.jsp
SESSNUM=4437 info.jsp
SESSNUM=4437 logout.jsp
And I enter this:
grep SESSNUM=4437 *
I get this information:
SESSNUM=4437 logout.jsp
SESSNUM=4437 welcome.jsp
SESSNUM=4437 login.jsp
SESSNUM=4437 info.jsp
Is there a way to make grep display matching lines in the order they appear in the log file(s)?
Thanks!
IVR Avenger
Best Answer
Grep normally returns thing in order. Are you sure you are getting the results from the correct log file? Does it work correctly if you specify the logfile you want instead of just *?
I would suggest you use the -H option of grep, so you can be sure you are getting the content from only one file. This should be the default behavior, but what you posted didn't include the filenames, unless you stripped those out.