-1

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.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
user2856064
  • 541
  • 1
  • 8
  • 25

3 Answers3

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

or

wc -l <test.csv | awk '{$1--}1' > output.txt
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
1

Or just the good old-fashioned:

expr $(wc -l < test.csv) - 1
William Pursell
  • 204,365
  • 48
  • 270
  • 300
0

Use this Perl one-liner:

perl -le 'print `wc -l <test.csv` - 1' > output.txt
Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47