-1

I am new to the Topic and working on a few bash commands.

I am stuck at a task where i Need t ouput my result in a specific Format.

wc -l folder/*

The Output gives me:

0 folder/file1
3 folder/file2
3 total

I would like to have only the total output together with a String like:

The total number of lines is: numberOfLines 

How is it possible to format my output / reduce it to a single line? I looked a bit into awk commands but I was not able to make it work.

Thank you very much in advance!

1 Answers1

1

The simplest way to get a grand total is to concatenate the files first, and pass the concatenation to wc.

Ex.

printf 'The total number of lines is: %d\n' "$(cat folder/* | wc -l)"

However if you want to use awk, here's how I'd do it:

wc -l folder/* | awk 'END{print "The total number of lines is: " $1}'
steeldriver
  • 142,475