Search code examples
shellwc

extract the total count line (wc -l) number in shell


I am trying to figure out how to extract the last total count number when I use "wc -l" on multiple files under a directory. For example:

currentDir$ wc -l *.fastq
    216272 a.fastq
    402748 b.fastq
   4789028 c.fastq
  13507076 d.fastq
   5818620 e.fastq
  24733744 total

I would only need to extract 24733744 from the above. I tried

wc -l *.fastq | tail -l

to get

  24733744 total

but not sure what to do next. If I use "cut", the annoying thing is that there are multiple spaces before the number, and I will need to use this code for other folders too, and the number of spaces may differ.

Any advice is appreciated. Thank you very much!


Solution

  • For this particular problem, it's probably easier to do :

    cat *.fastq | wc -l