Frage

I able to do single grep but can not do OR search in unix solaris

Please see below examples i tried...

-bash-3.00$ echo "Hello hi" | grep -i "Hello"
Hello hi
-bash-3.00$ echo "Hello hi" | grep -i "Hello\|hi"
-bash-3.00$ 
War es hilfreich?

Lösung

You can make use of egrep, which per definition is the same as grep -E. It interprets the patterns as extended regular expressions, so that grep -E "hello|hi" means: "grep either hello or hi".

So both of these should work:

echo "Hello hi" | egrep -i "hello|hi"  # as you are using -i, no need to low/upper case

echo "Hello hi" | grep -Ei "hello|hi"

In case of doubt, you can always check your man grep and see what they explain there. As I do not have access to any Solaris server, I cannot test myself.

Andere Tipps

You can also use awk for this:

echo "Hello hi" | awk '/Hello|Hi/'
Hello hi
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top