I want to just compare the number of lines in two files. Below is the list of names of files. One file contains names/location of fastq files; the other file contains names/location of bam files.

File1 (consists of fastq files)


File2 (consists of bam files)



if [ "wc -l $File1" == "wc -l $File2" ] ; then
  echo "Bam files from File2 do exist for each sample"
  echo "Bam files do not exist for every sample"

There is some error in my code, as I always get the statement from else that is "Bam files do not exist" whereas the count remains same in both File1 and File2.

  • 3
    Save the no. of lines in variables and compare them e.g. fastq=$(wc -l <file1); bam=$(wc -l <file2); if [ $fastq -eq $bam ]... or without vars if [ $(wc -l <file1) -eq $(wc -l <file2) ]... – don_crissti May 26 '16 at 20:34
  • Or even use command substitution at the condition line if [ $(wc -l < /path/to/the/file1) -eq $(wc -l /path/to/the/file2) ] then ... – tachomi May 26 '16 at 20:52
  • is comparing line counts adequate? is it possible for there to be duplicate entries in either file? or just equal numbers of files, without any actual connection between some of the files in File1 and/or some in File2? – cas May 27 '16 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.