Skip to content

Instantly share code, notes, and snippets.

@uabassguy
Created June 7, 2017 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uabassguy/f65c6310b68bfefcb626d4d917767f92 to your computer and use it in GitHub Desktop.
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
#!/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