awk if statement to evaluate string and compare

I have the following simplified code that I am planning on putting into a larger shell script. I have been butchering it to try and make work amongst google searches and reading awk documentation.

amixer sset Master toggle | awk '{ if ( /^  Front Left/ { print $7 } == /[off]/ ) print "MUTED" }'

I want to evaluate the output from the syntax below and compare it with the value "[off]" and print the word "MUTED" if it matches.

amixer sset Master toggle | awk '/^  Front Left/ { print $7 } '

The command essentially outputs either [on] or [off]

I have been unable to find an example and I'm not even sure it could be done - Would an awk guru please provide some insight.

The input to awk from the amixer command looks like this for anyone that does not have amixer available and would like to test using a text file (the [off] becomes [on] and visa versa each time the command is executed).

Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 74
  Mono:
  Front Left: Playback 50 [68%] [-24.00dB] [off]
  Front Right: Playback 50 [68%] [-24.00dB] [off]

Thanks

Try this...

amixer... | awk '/^  Front Left/{if($7~"[off]"){print "MUTED"}}'

--ahamed

1 Like

You Rule!! Thanks