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
  • 730,956
  • 141
  • 904
  • 1,278
mcExchange
  • 6,154
  • 12
  • 57
  • 103

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
  • 11,533
  • 5
  • 49
  • 56
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
  • 94,125
  • 30
  • 188
  • 241
1

You can try

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