Search code examples
bashcutwc

using cut command in bash


I want to get only the number of lines in a file: so I do:

$wc -l countlines.py 
   9 countlines.py

I do not want the filename, so I tried

$wc -l countlines.py | cut -d ' ' -f1

but this just echo empty line.

I just want number 9 to be printed


Solution

  • Use stdin and you won't have issue with wc printing filename

    wc -l < countlines.py