0

We want to search the following line recursive under folder/s

awk '{print}'|grep -i -e 'port is up' -e 'valid output'

so we did that:

grep -r "awk '{print}'|grep -i -e 'port is up' -e 'valid output'"  /var
grep -r "awk '{print}'|grep -i -e 'port is up' -e 'valid output'"  /etc
grep -r "awk '{print}'|grep -i -e 'port is up' -e 'valid output'"  /opt

but I am not sure if grep can managed the " ' " and "{" characters or maybe my syntax is wrong?

  • Are you sure that's the awk program you're searching for? It's just passing on its input... Ah well, you want the -F option for grep to search for a fixed string, and possibly -x to force a whole line match. What grep implementation are you using? GNU grep I presume? – Kusalananda Jul 8 '18 at 18:35
  • yes I am sure that we need to search the awk '{print}'|grep -i -e 'port is up' -e 'valid output' – yael Jul 8 '18 at 18:36
1

To search for a fixed string (not a regular expression), use the -F option with grep. If you additionally need to make sure that your string matches an entire line, use -x:

grep -Fx -r '...your string here...' directory

To get approximate hits (if a full line search doesn't return anything), I would start with just port is up (without -x), or possibly

grep -F -r -e 'port is up' -e 'valid output' directory

Neither | nor { or } are special in a regular expression pattern when you're using basic regular expression as you do here. ' is never special in a regular expression. However, since you are searching with a string (not a pattern), you should nonetheless use -F.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.