0

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)

Jonathan Leffler
  • 698,132
  • 130
  • 858
  • 1,229
mcExchange
  • 5,605
  • 12
  • 52
  • 87

3 Answers3

3

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.

Anthony Geoghegan
  • 10,874
  • 5
  • 46
  • 55
1

You can use cat and pipe wc -l:

cat myFile.txt | wc -l

Or if you insist wc -l be the first command, you can use awk:

wc -l myFile.txt | awk '{print $1}'
Maroun
  • 91,013
  • 29
  • 181
  • 233
1

You can try

wc -l file | awk '{print $1}'