Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • A follow up question: After a while, the MasterFile.txt will have thousands of entries. Do you recommend a faster/more efficient way of searching for the strings? Commented May 31, 2017 at 16:06
  • @Ptheguy Using grep - q is already very fast, as it will quit as soon as it finds a match. The other thing you may try is to make the pattern more specific. This may possibly be done by anchoring the pattern to the beginning and/or end of the line (I haven't benchmarked to see if this actually makes a difference). Commented May 31, 2017 at 16:15
  • You can use grep -ql, which will stop at the first match rather than proceeding through the rest of the file. Commented May 31, 2017 at 16:15
  • 2
    A syntax highlighting editor would also be a good tool to spot issues like this, though it might be that they'll just highlight the whole quoted string with one color. shellcheck.net warns about unset variables, though... Commented May 31, 2017 at 17:04
  • 1
    vim seems to DTRT: i.imgur.com/4QJwi88.png Also, you can set -u to make referencing an unset or undeclared variable an error condition which will cause the script to terminate. Commented May 31, 2017 at 17:15