title: How To Compare Number Of Lines In 2 Files Using IF/Then Bash Command
body: <p>I would like to compare the line counts of two separate files. While I have tried using <code>wc -l</code> in the comparison, I'm struggling to get it working properly.</p>
  
  <p>I have:</p>
  
  <pre><code>if [ "$(wc -l file1.txt)" == "$(wc -l file2.txt)" ]; then echo "Warning: No Match!"; fi
  </code></pre>
  
  <p>However, the if/then statement does not return the correct output.</p>
  
  <p>If file 1 and 2 have the same number of lines, what is the proper way of writing this code?</p>
  
  <p>File1.txt:</p>
  
  <pre><code>example1
  example2
  example3
  </code></pre>
  
  <p>File2.txt:</p>
  
  <pre><code>example4
  example5
  example6
  </code></pre>
  
  <p>Update: We found that the <code>wc -l</code> command must return a digit only for the comparison. Unlike the question <a href="https://stackoverflow.com/questions/9581064/why-should-there-be-a-space-after-and-before-in-bash">Why should there be a space after &#39;[&#39; and before &#39;]&#39; in Bash?</a>, this question requires using <code>wc -l</code> to get an integer that can be compared the number of lines in separate files.</p>