I'm trying to grep all line breaks after some binary operators in a project using git bash on a Windows machine.
Tried the following commands which did not work:
$ git grep "[+-*\|%]\ *\n"
fatal: command line, '[+-*\|%]\ *\n': Invalid range end
$ git grep "[+\-*\|%]\ *\n"
fatal: command line, '[+\-*\|%]\ *\n': Invalid range end
OK, I don't know how to include "-" in a character set, but still after removing it the \n
matches the character n
literally:
$ git grep "[+*%] *\n"
somefile.py: self[:] = '|' + name + '='
^^^
Escaping the backslash once (\\n
) has no effect, and escaping it twice (\\\n
) causes the regex to match \n
(literally).
What is the correct way to grep here?
grep '[-+*|%]\s*$'
to account for windows line endings. It turns out that I could also find the answer in grep manual. See also: Is it better to use git grep than plain grep if we want to search in versioned source code? – Gschu