You are not logged in.

#1 2009-06-28 13:13:01

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

[SOLVED] Sed problem

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

#2 2009-06-28 13:21:29

arkham
Member
From: Stockholm
Registered: 2008-10-26
Posts: 516
Website

Re: [SOLVED] Sed problem

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

#3 2009-06-28 13:23:19

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] Sed problem

... | grep -Eo "[0-9]{1,3}%" | sed 's/%//g'

is my hackish way, I'm sure procyon's got a cleaner approach tho...

Offline

#4 2009-06-28 13:28:05

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: [SOLVED] Sed problem

arkham wrote:

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 }'

That's quite ok smile 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 smile

Offline

#5 2009-06-28 13:29:31

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED] Sed problem

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

#6 2009-06-28 13:50:46

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: [SOLVED] Sed problem

Procyon wrote:
amixer get Front | sed -n '${s/.*\[\([0-9]*\)%\].*/\1/p}'

Awesome!

Offline

Board footer

Powered by FluxBB