Grep result from dd command

Hi,

I am running following command in a bash script for testing IO and use grep to get throughput number, but it did not work, it displayed everything:

dd if=/dev/zero of=/dev/null bs=1G count=1 oflag=dsync | grep bytes | awk '{print $7}'

1+0 records in
1+0 records out
536870912 bytes (537 MB) copied, 8.857 s, 60.6 MB/s

How can I extract only the result "60.6 MB/s"?

Also, can I have timeout if it takes too long?

Thank you

Try:

dd .... 2>&1 | grep ....
1 Like

In addition to what Scrutinizer said, $7 in the last line of output from dd is s, ; not 60.6 MB/s . And you don't need both grep and awk . Try:

dd if=/dev/zero of=/dev/null bs=1G count=1 oflag=dsync 2>&1 | awk '/bytes/{print $(NF-1), $NF}'
1 Like