Mike
Mike

Reputation: 1

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!

Upvotes: 0

Views: 208

Answers (1)

Dennis Williamson
Dennis Williamson

Reputation: 360325

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

Upvotes: 1

Related Questions