simple approach to finding files that contain two patterns; it's easy to find a file...
authorChris Koeritz <fred@gruntose.com>
Wed, 10 Dec 2014 21:24:22 +0000 (16:24 -0500)
committerChris Koeritz <fred@gruntose.com>
Wed, 10 Dec 2014 21:24:22 +0000 (16:24 -0500)
scripts/text/grep_two_patterns.sh [new file with mode: 0644]

diff --git a/scripts/text/grep_two_patterns.sh b/scripts/text/grep_two_patterns.sh
new file mode 100644 (file)
index 0000000..6ba4097
--- /dev/null
@@ -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"
+