Amazon Interview Question
Software Engineer / DevelopersWith this question they just want to know if you know about any scripting languages.. any scripting language will do bash/python/perl. c++/java code in this Q may reduce your chances of getting selected unless its an astonishing solution
If its just for one time then following grep command like:
grep -lr '[1-9]\{3\}-[0-9]\{4\}-[0-9]\{3\}' "*.html" > results.txt
Yeah I was a little confused when I got the question, because I didn't see where the challenge was... I think I ended up just saying something about using a regular expression. You're right that this question may be just aimed at testing UNIX proficiency - it may also be about to what degree will you ask questions to clear up ambiguity (I know microsoft likes doing that).
grep -lr "[0-9]\{3\}[ -][0-9]\{3\}[ -][0-9]\{4\}"*
this would return numbers of the format 123-456-7890
but would also return 123-456-78901
is there a way to restrict the digits to a specic number, coz when we specify 3 it means minimum 3
I had a problem with Grep when there were too many files. It gave me an exception that there are too many files. So I had to use a commbination of "find" and "exec" to locate all the files that I was looking for. something like: (can't remember exactly)
find . -name ".html" | exec ...pattern matching... /?
I am not sure if I did something wrong here..
If I think this in terms of .Net then I would open up each html file as an XMLDocument, do an XPath query to check if such an XmlNode exist. If yes, will check if the XmlNode has any InnerText (which in this case will be the phone no.). If yes, then will add this file to the List<String> collection.
if its to be run at the prompt then it would be a perl script that holds the corresponding regular expression to check for phone no. formats.
(last option as HTML docs arent generally wellformed) if its a well-formed HTML document, I would use a small sax java program that would read entire html and go fetch that particular tag's data alone.
would it have any meta data tags to indicate phone no.s in them ?
I also forgot grep when I was asked this question in an interview. I said I would write a Java program with the PatternMatcher. The interviewer said "Well your method if fine if we need to repeat it several times but for once, you can use grep".
- Prathibha Hegde June 08, 2005