grep1-1 Exercise 1: A Word in Any Case, Without the Pies ========================================================= cat > inventory.txt <<'EOF' Apple juice apple pie pineapple green apple APPLE sauce crab apples EOF # the word apple, any case, not part of a longer word grep -iw apple inventory.txt echo --- # ...and not the pies: the first grep's output is the second grep's input grep -iw apple inventory.txt | grep -v pie Output: Apple juice apple pie green apple APPLE sauce --- Apple juice green apple APPLE sauce WHY THIS WORKS AS AN ANSWER --------------------------- -i makes Apple, apple and APPLE all match; -w refuses pineapple (the letters before 'apple' make it part of a longer word) and crab apples (the 's' after it does). That leaves four lines. The second command reads the first one's output on its standard input (no file name given) and -v drops the line that mentions pie. Combining -i and -w in one option group (-iw) is the same as -i -w.