title: Grep No such file or directory Error In Bash Script, Should I Insert Wait Command?
body: <p>I am running a script that has been working fine. However, yesterday, I got a couple errors. <strong>These errors are after several loops of the script:</strong> </p>
  
  <pre><code>sed: cant read file3.txt: No such file or directory
  grep: file3.txt: No such file or directory
  grep: file3.txt: No such file or directory
  sed: cant read file3.txt: No such file or directory
  grep: file3.txt: No such file or directory
  </code></pre>
  
  <p>Keep in mind, these errors do not happen consistently. It's occurring once in a while somewhere near this part of the script. <strong>File3.txt is the file not being found:</strong></p>
  
  <pre><code>cat file1.txt | while read LINE; do grep -m 1 $LINE file2.txt &gt;&gt; file3.txt; done
  sed -i 's/string//g'  file3.txt
  grep 'string' file3.txt | cut -d '|' -f1-2 &gt; file4.txt
  grep -v 'string' file3.txt | cut -d '|' -f1-2 &gt;&gt; file5.txt
  sed -i 's/string//' file3.txt
  grep -Fvf file3.txt file1.txt &gt; file6.txt
  </code></pre>
  
  <p>Now, I'm thinking that since file3.txt is being appended, or later operated on by SED, sometimes the next command starts too soon and it can't find the file? Should I put a wait command in between?</p>
  
  <p>I have looked up many pages with this error, but was unable to find anything:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/28624227/cat-file-name-grep-something-results-cat-grep-no-such-file-or-directory">cat file_name | grep &quot;something&quot; results &quot;cat: grep: No such file or directory&quot; in shell scripting</a></li>
  <li><a href="https://stackoverflow.com/questions/13195285/pipe-multiple-commands-to-a-single-command-with-no-eof-signal-wait">Pipe multiple commands to a single command with no EOF signal wait</a></li>
  <li><a href="https://stackoverflow.com/questions/34173389/grep-command-works-in-command-line-but-not-in-bash-script-get-no-such-file-or">grep command works in command line, but not in bash script: get no such file or directory erro</a></li>
  <li><a href="https://serverfault.com/questions/169539/sed-cant-find-a-file-that-obviously-exists">https://serverfault.com/questions/169539/sed-cant-find-a-file-that-obviously-exists</a></li>
  <li><a href="https://stackoverflow.com/questions/3949161/no-such-file-or-directory-but-it-exists">&quot;No such file or directory&quot; but it exists</a></li>
  </ul>
  
  <p>If you think that putting a wait or sleep command will help, please let me know. Or, if you think there's a better solution, that would be great too. I'm running on Cygwin terminal. Any insight is greatly appreciated. </p>