Skip to content

Instantly share code, notes, and snippets.

@dmd
Created December 13, 2022 18:58
Show Gist options
  • Save dmd/f5a30a2efa8f0aaf72008e1247d53c99 to your computer and use it in GitHub Desktop.
Save dmd/f5a30a2efa8f0aaf72008e1247d53c99 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Read the patterns from the file PATTERNS.txt and store them in an array
patterns=()
while IFS= read -r line; do
patterns+=("$line")
done < PATTERNS.txt
# Iterate over the patterns array and compare each pair of patterns
for ((i=0; i<${#patterns[@]}; i++)); do
for ((j=0; j<${#patterns[@]}; j++)); do
# Count the number of lines in TEXT.txt that contain both patterns as words
count=$(grep "\b${patterns[i]}\b.*\b${patterns[j]}\b" TEXT.txt | wc -l)
if (( $count > 0 )); then
echo "$count ${patterns[i]} ${patterns[j]}"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment