Search code examples
bashwc

Get first argument of wc -l myFile.txt


I'm counting the number of lines in a big file using

wc -l myFile.txt

Result is

110 myFile.txt

But I want only the number

110

How can I do that? (I want the number of lines as an input argument in a bash script)


Solution

  • There are lots of ways to do this. Here are two:

     wc -l myFile.txt | cut -f1 -d' '
    
     wc -l < myFile.txt
    

    Cut is an old Unix tool to

    print selected parts of lines from each FILE to standard output.