Score:0

How to exclude words using grep?

ro flag

Instead of me chaining these like 10 times

cat /var/log/nginx/access.log | grep -v download | grep -v danger | grep -v "/visitor/return" | grep -v welcome | grep -v "GET / HTTP" | grep -v "/baby/" | grep -v "/paste/" | awk '{ print $1, $4, $7 }' >> access.$(date "+%Y-%m-%d").txt

Is there a way to combine them into a list or an array for a bit cleaner to read ?


I tried

grep -wv 'download|danger|/visitor/return|welcome|GET / HTTP|/baby/|/paste/' | awk '{ print $1, $4, $7 }' >> access.$(date "+%Y-%m-%d").txt

no luck, even with -v only


I thinking I'm setting here for the best

cat /var/log/nginx/access.log | grep -v -e "download" -e "danger" -e "/visitor/return" -e "welcome" -e "GET / HTTP" -e "/baby/" -e "/paste/" | awk '{ print $1, $4, $7 }' >> access.$(date "+%Y-%m-%d").txt

If you guys know a better one, I would like to learn from you. !

Score:0
zw flag

You may use the -Ev flag:

grep -Ev 'house|garden' file.txt

will show all lines that do not the words "house" or "garden".

  1. -E: Interpret PATTERN as an extended regular expression
  2. -v: Invert the sense of matching, to select non-matching lines.

An alternative would be the -v flag with egrep:

egrep -v '(house|garden)' file.txt
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.