I have this particular file with special characters:
^S^H^B^R^MLong is here
^X^M
When I search for it via grep -r "Long is here" . it will give me the following as result, not revealing its file path:
Long is here
However, if I remove the ^S^H^B^R^M, the file path will show up:
./CIQla:Long is here
I'm using OSX.
What's going on here?
EDIT:
I tried it with both BSD grep (grep 2.5.1-FreeBSD) as GNU grep (ggrep 2.26)
The ^M is a carriage return, which makes the terminal return to the beginning of the line. Essentially, it prints "./CIQla:", then several nonprinting characters, then ^M sends it to the beginning of the line, then it prints "Long is here" over the "./CIQla:".
If you want to be able to see the filename in the output, you need to pipe the result through something that'll make the ^M (and probably the other nonprinting characters) into something printable. Try these:
grep -r "Long is here" . | cat -v
grep -r "Long is here" . | more
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With