开发者

how to trim wipe output with sed?

开发者 https://www.devze.com 2023-02-03 16:35 出处:网络
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\'

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
0

精彩评论

暂无评论...
验证码 换一张
取 消