在 shell 中提取总计数行 (wc -l) 数
extract the total count line (wc -l) number in shell
当我对一个目录下的多个文件使用 "wc -l" 时,我想弄清楚如何提取最后的总计数。例如:
currentDir$ wc -l *.fastq
216272 a.fastq
402748 b.fastq
4789028 c.fastq
13507076 d.fastq
5818620 e.fastq
24733744 total
我只需要从上面提取 24733744。我试过了
wc -l *.fastq | tail -l
获得
24733744 total
但不确定下一步该做什么。如果我使用 "cut",烦人的是数字前有多个空格,我也需要将此代码用于其他文件夹,并且空格数可能会有所不同。
如有任何建议,我们将不胜感激。非常感谢!
对于这个特定的问题,可能更容易做到:
cat *.fastq | wc -l
这应该适用于任意数量的空格:
wc -l *.fastq | tail -l | tr -s ' ' | cut -f 2 -d ' '
示例:
echo " 24733744 total" | tr -s ' ' | cut -f 2 -d ' '
24733744
当我对一个目录下的多个文件使用 "wc -l" 时,我想弄清楚如何提取最后的总计数。例如:
currentDir$ wc -l *.fastq
216272 a.fastq
402748 b.fastq
4789028 c.fastq
13507076 d.fastq
5818620 e.fastq
24733744 total
我只需要从上面提取 24733744。我试过了
wc -l *.fastq | tail -l
获得
24733744 total
但不确定下一步该做什么。如果我使用 "cut",烦人的是数字前有多个空格,我也需要将此代码用于其他文件夹,并且空格数可能会有所不同。
如有任何建议,我们将不胜感激。非常感谢!
对于这个特定的问题,可能更容易做到:
cat *.fastq | wc -l
这应该适用于任意数量的空格:
wc -l *.fastq | tail -l | tr -s ' ' | cut -f 2 -d ' '
示例:
echo " 24733744 total" | tr -s ' ' | cut -f 2 -d ' '
24733744