Created
June 7, 2017 22:26
-
-
Save uabassguy/f65c6310b68bfefcb626d4d917767f92 to your computer and use it in GitHub Desktop.
Read lines from a file then search a different file using those values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Accepts in.txt as input | |
# Uses strings found in search.txt | |
# Outputs to out.txt | |
# Test if in.txt exists in pwd | |
if [ ! -f in.txt ]; then | |
echo "Input data file not found. Please create in.txt" | |
exit 1; | |
fi | |
# Test if search.txt exists in pwd | |
if [ ! -f search.txt ]; then | |
echo "Search list file not found. Please create search.txt with 1 search string per line" | |
exit 1; | |
fi | |
# Execute search | |
while read word; do | |
grep "$word" in.txt; | |
done <search.txt >out.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment