How to grep an exact string with slash in it?
问题 I'm running macOS. There are the following strings: /superman /superman1 /superman/batman /superman2/batman /superman/wonderwoman /superman3/wonderwoman /batman/superman /batman/superman1 /wonderwoman/superman /wonderwoman/superman2 I want to grep only the bolded words. I figured doing grep -wr 'superman/|/superman' would yield all of them, but it only yields /superman. Any idea how to go about this? 回答1: You may use grep -E '(^|/)superman($|/)' file See the online demo: s="/superman