Find and replace interview question

We’ve recently been searching for a junior sysadmin to join the team (and I’m very happy to say we’ve now succeeded) so as part of my day to day tasks I had to come up with a dozen simple questions to weed out the people that have never used anything but webmin (and there is a surprising number of them out there). One of the questions seemed to cause a lot of trouble in the general sense and tripped up the few who even made an attempt -

How would you change all occurrences of 10.23.34.10 to 10.23.34.101 in a text file?

While most of the candidates failed this one on account of skipping the question we had a couple make attempts (oddly all using the vim replace syntax). While I was hoping for a little bit of sed or perl a solution’s a solution. Unfortunately theirs all had edge cases.

First was the obvious trick in the question. All the answers (apart from one) came back with something like this - %s/10.23.34.10/10.23.34.101/. First up we have the missing boundary test. While that regex is fine for 10.23.34.10 it breaks quite badly on 10.23.34.101 (it replaces it with 10.23.34.1011). Secondly the dots are unescaped, which means it’s not only going to work on IPs, but number sequences.

I was actually really surprised at how few of the admins could write an awk / perl / shell script and how many paid very little attention to what the regex actually matched. Still, while the question seemed easy enough it had enough awkwardness to enable further discussion about regexs, data checking and the evil of manual changes. And it showed that everybody likes vim :)