how to trim wipe output with sed?
i want to trim an output of wipe command with sed. i try to use this one:
wipe -vx7 /dev/sdb 2>&1 | sed -u 's/.*\ \([0开发者_开发知识库-9]\+\).*/\1/g'
but it don't work for some reason.
when i use echo & sed to print the output of wipe command it works!
echo "/dev/sdb: 10%" | sed -u 's/.*\ \([0-9]\+\).*/\1/g'
what i'm doing wrong?
Thanks!
That looks like a progress indicator. They are often output directly to the tty instead of to stdout or stderr. You may be able to use the expect
script called unbuffer
(source) or some other method to create a pseudo tty. Be aware that there will probably be more junk such as \r
, etc., that you may need to filter out.
Demonstration:
$ cat foo
#!/bin/sh
echo hello > /dev/tty
$ a=$(./foo)
hello
$ echo $a
$ a=$(unbuffer ./foo)
$ echo $a
hello
精彩评论