Line At A Time
Level 17: Searching Inside Files
Searching Inside Files Find every line of a file that contains a word.

grep searches inside files and prints every line that contains what you asked for. The name comes from an old text-editor command, g/re/p, and once you know grep you will use it forever.

Read it as: in shopping.txt, show me the lines containing an a. Notice it prints whole lines, not just the matching letter.

If nothing matches, grep prints nothing at all: no news is good news. Add -i to ignore capital letters, or -n to number the lines it found.

grep "a" shopping.txtLines containing an a.
grep -i "MILK" shopping.txtIgnore capitals.
grep -n "bread" shopping.txtShow line numbers too.
Your task
  • Search shopping.txt for a letter or word
  • Search one of the files in notes

Open this level in your browser to type the commands at a live terminal that answers back.