Search code examples
bashcountlineswc

How to count lines in a file and add an arbitrary number to the result?


I have a file that contains 'x' lines in it.

I need to display the number of lines in such file and add 'y'.

I know that wc -l does the trick and displays 'x' as the output, how can it be so that the output would be 'x+y'?


Solution

  • You could do like this,

    $ wc -l file
    13 yi
    $ y=12
    $ wc -l file | awk -v var=$y '{print $1+var}'
    25