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!
There is no portable way to tell the amount of data coming from a pipe. The only thing you could do is to read and process data as it comes. Save this answer.
Simple piping uses | character to send the STDOUT from one application to the STDIN of the next application. One nice thing about piping in Linux is that each application that is executed is run in parallel, so each application is processing its STDIN and sending its STDOUT as soon as it is received.
if stdin/stdout are connected to a terminal then default size = 1024; else size = 4096.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With