I have a script in which I am running this command:

pv -s `du -sb file1.data | awk '{s += $1} END {print s}'`

And it gives below error:

pv: -s: integer argument expected

So when I ran this command du -sb file1.data | awk '{s += $1} END {print s}', it looks like output coming as:


So how can I solve this issue?

  • This depends (at least) on your version of awk and on which system you are on. Try using printf instead of s +=, you can also modify the output way easier. But allow me one question: why? What do you use this statement for? – Lenniey Feb 28 '18 at 7:40

Just format it using printf:

du -sb file1.data | awk '{s += $1} END {printf "%d\n", s}'

Or maybe you need %ld for really huge numbers:

du -sb file1.data | awk '{s += $1} END {printf "%ld\n", s}'

And if that fails (like I tested on FreeBSD with numbers like 1e32), then try this:

du -sb file1.data | python -c $'import sys\nt=0\nfor line in sys.stdin:\n    t += int(line.split()[0])\nprint(t)'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.