0

Is there a command I can use to find a certain word in a file? I tried using the find command without any success.

muru
  • 193,181
  • 53
  • 473
  • 722

1 Answers1

4

Yep. grep will be your friend here.

Simply do something like this:

cat file.txt | grep wordtomatch
You'reAGitForNotUsingGit
  • 14,669
  • 9
  • 48
  • 83
  • 3
    Or just `grep wordtomatch file.txt` ;) – Seth May 08 '17 at 23:52
  • 3
    [UUOC](https://en.wikipedia.org/wiki/Cat_(Unix)#Useless_use_of_cat) - also, strictly speaking, grep matches *basic regular expressions* by default; to avoid surprises (in case `wordtomatch` contains regex special characters) it might be safer to add the `-F` (`--fixed-strings`) option – steeldriver May 08 '17 at 23:52
  • 2
    And if you **really** wanted to catch all the fish, you'd use `grep -i word_to_find filename` so that you'd match both upper and lower case letters. – heynnema May 09 '17 at 00:08