For my work, I often look for patterns in files. I usually use grep --color=auto to color the search pattern. Now, when I search for several patterns, all of which should be present in the string, I use grep pattern1 file|grep pattern2|grep pattern3 or awk '/pattern1/&&/pattern2' . But in this way, in grep, I lose color, which is very useful for me, or in awk, I donβt know how to color only a template line. When this gets too troublesome, I use grep pattern1 file|grep pattern2|grep pattern3|grep -E "pattern1|pattern2|pattern3" .
So, is there a way to grep to specify multiple patterns and conditions? (I think that regular expressions should support it, but could not find them, especially the ordering of the patterns is not fixed)
Or is there a way to color print awk search patterns?
Any short compact approach is welcome (I will use it many times a day)
abasu
source share