I have a program in which I load text from a file and then filter it according to one of the fields. What I am interested in is the size of the data after this filtering step.

Ideally, I would be able to do something like: awk '$2>=10' <myfile | du -

I could just apply the filter and save the output somewhere, call du on it, and then delete the file, but the file is quite large, so writing to disk could take a while.

Recognizing that du stands for "disk usage", I suspect I am asking something that makes no sense, given how the program works. If there is another common utility that will do this, please suggest it!

有帮助吗?

解决方案

You can pipe it to wc -c to count the number of bytes that goes through the pipeline.

其他提示

du stands for "disk usage". Data in a pipe doesn't hit the disk, so there's no "du" to work with. use wc instead, which is "word count".

awk '$2>=10' < myfile | wc -c

The -c flag counts bytes.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top