From: Chris Koeritz Date: Wed, 10 Dec 2014 21:24:22 +0000 (-0500) Subject: simple approach to finding files that contain two patterns; it's easy to find a file... X-Git-Tag: 2.140.90~733 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=42fc4d3fd60ae9e1791c52a507c220eec8f39fb9;p=feisty_meow.git simple approach to finding files that contain two patterns; it's easy to find a file that has one pattern or the other, but grep doesn't offer an option saying "both of these must be present". --- diff --git a/scripts/text/grep_two_patterns.sh b/scripts/text/grep_two_patterns.sh new file mode 100644 index 00000000..6ba40978 --- /dev/null +++ b/scripts/text/grep_two_patterns.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +folder="$1"; shift +pat1="$1"; shift +pat2="$1"; shift + +if [ -z "$pat1" -o -z "$pat2" ]; then + echo "this script requires a folder and two patterns to search." + echo "all files in the folder (and sub-folders) that contain both patterns" + echo "will be displayed." + exit 1 +fi + +find "$folder" -type f -exec grep -lZ "$pat1" ';' | xargs -0 grep -l "$pat2" +