Amazon Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: Phone Interview
Duplicate of the other question that you posted. At the risk of being redundant, here is the possible answer
I am sure you can achieve this by using sed or awk in a more elegant way but here are the other ways
grep "^ERROR" <YOUR LOG FILE NAME"
cut -d " " -f1 <YOUR LOG FILE NAME> | grep "ERROR"
The "cut" command assumes that your log file delimiter is a space.
I think the interviewer expects implementation rather then direct use of library/language/shell function.
Oh sorry about that. Since the question didn't have any references to implementation, I thought the usage of a tool is acceptable.
Like you said, we could use brute force. Just that instead of checking for \n, we could stop soon after we reach the character length of search string or 5 in case of "ERROR"
No need to be sorry about that, nice quick solution though, who knows interviewer might also get impressed seeing your scripting skills :)
I am sure you can achieve this by using sed or awk in a more elegant way but here are the other ways
- Arun Manivannan August 28, 2012grep "^ERROR" <YOUR LOG FILE NAME"
cut -d " " -f1 <YOUR LOG FILE NAME> | grep "ERROR"
The "cut" command assumes that your log file delimiter is a space.