You are not logged in.
Pages: 1
Hi
I'm struggling on this issue, I want to filter out information from amixer output, when I do
amixer set Master 0%+ | sed -e '$!d'
I get
Mono: Playback 64 [100%] [0.00dB] [on]
And now I only want the "100". I tried a lot and I know how to exclude the part I need by doing
amixer set Master 0%+ | sed -e '$!d; s/\[[0-9]*%\]//g'
but I can't figure out how to revert the substitute and remove everything but the matched piece.
Any help is greatly appreciated.
Last edited by Ramses de Norre (2009-06-28 13:53:28)
Offline
What about
amixer set Master 0%+ | sed -e '$!d' -e 's/[][%]//g' | awk '{ print $5 }'
?
Edit: My output of that command is one word longer (Front Right instead of Mono)
Try this instead
amixer set Master 0%+ | sed -e '$!d' -e 's/.*://' -e 's/[][%]//g' | awk '{ print $3 }'
Last edited by arkham (2009-06-28 13:25:34)
"I'm Winston Wolfe. I solve problems."
~ Need moar games? [arch-games] ~ [aurcheck] AUR haz updates? ~
Offline
What about
amixer set Master 0%+ | sed -e '$!d' -e 's/[][%]//g' | awk '{ print $5 }'
?
Edit: My output of that command is one word longer (Front Right instead of Mono)
Try this insteadamixer set Master 0%+ | sed -e '$!d' -e 's/.*://' -e 's/[][%]//g' | awk '{ print $3 }'
That's quite ok Just for me to learn, why does the substitute clause delete all square brackets and [ %] ? There are no wildcards and stuff used?
PS: If someone knows how to write this in pure sed, show us
Offline
I posted about this in awk recently:
http://bbs.archlinux.org/viewtopic.php? … 93#p575393
If you want to do it with sed, you would have to use \(......\) and a way to avoid making the second * glob nothing because of the first .* with \[
amixer get Front | sed -n '${s/.*\[\([0-9]*\)%\].*/\1/p}'
BTW you can also check for muted state in sed
amixer get Front | sed -n '${s|\[off\]|&|;tmuted;s/.*\[\([0-9]*\)%.*/\1/p;q;:muted;s/.*/MM/p}'
Offline
amixer get Front | sed -n '${s/.*\[\([0-9]*\)%\].*/\1/p}'
Awesome!
Offline
Pages: 1