A couple of days ago I was playing around with
sed in Mac just for fun, and came up to a quite confusing issue: I could not match NAME using
/NAME/ as a context address. In fact, trying to match anything using a longer-than-2-chars regexp would not work:
/NA/ would match NAME /AM/ would match NAME /ME/ would match NAME /NAM/ would not match NAME /AME/ would not match NAME
This was quite puzzling. After trying different things and looking around the internet I was still where I had started. Then I decided to try using small letters:
/th/ would match many different lines in the input file /the/ would match many different lines in the input file
Woah! I could use longer-than-2-chars with small case letters, but not with capital ones. WTF? I continued trying with different combinations using capital letters, and anything with 1 or 2 chars would work, but more than 3 chars wold fail to match anything even though there seemed to be matches in the input file.
After a long time with this I decided to check the input file as a last act of hope. I found the problem.
At this point I should tell you how I got the input file. Remember how I said I was just practicing some
sed. Well, I thought that an easy way to get a practice input file would be to put the contents of the man page for
sed in a regular text file:
man sed > input_file
Well, that was not the best idea. My file ended up something like:
I didn’t notice that when I fist made the file because ^H is a
BS control character, and doing
produces the expected text NAME because cat interprets those control characters, but opening the input file in vim revealed the control characters.
This is one of those life lessons that you never really forget, but if you do, you will feel stupid the next time you have to re-learn it. Read the input file in a text editor.