Search code examples
bashawkcatwc

Substract number from wc cmd in one line


Let's suppose test.csv contains 10 lines. I'd like to put 9 into output.txt in one command line. I tried:

cat test.csv | $(wc -l) - 1 > output.txt

output.txt should contain 9.


Solution

  • echo $(( $(wc -l <test.csv) - 1 )) > output.txt
    

    or

    wc -l <test.csv | awk '{$1--}1' > output.txt