-1

I am wondering is there an easy way to ignore search result output lets say like a $pacmd list-modules | grep -e 'name: <module-cli-protocol-unix>' -e 'argument: '

in this case the output is giving if argument has values or if it doesn't.

The $pacmd list-modules input format snippet:

...    
index: 5#<---not this index because the module's module-cli-protocol-unix arg is empty
name: <module-cli-protocol-unix>#<---not this name though its name is module-cli-protocol-unix but still its arg is empty
argument: <>#<---not this module's arg because it is empty
used: -1
load once: yes
properties:
    module.author = ""
    module.description = ""
    module.version = "10.0"
index: 6
name: <module-switch-on-port-available>
argument: <>
used: -1
load once: no
properties:

index: 7
name: <module-udev-detect>
argument: <>
used: -1
load once: yes
properties:
    module.author = "Lennart Poettering"
    module.description = "Detect available audio hardware and load matching drivers"
    module.version = "10.0"
index: 8
name: <module-bluetooth-policy>
argument: <>
used: -1
load once: yes
properties:
    module.author = "Frédéric Dalleau, Pali Rohár"
    module.description = "Policy module to make using bluetooth devices out-of-the-box easier"
    module.version = "10.0"
index: 9 #<---this one because it is the module-cli-protocol-unix index
name: <module-cli-protocol-unix>#<---this one because its name is module-cli-protocol-unix
argument: <sink_name=module-cli_>#<---this one because module's arg is not empty
used: -1
load once: yes
properties:
    module.author = ""
    module.description = ""
    module.version = "10.0"
index: 10
name: <module-bluez5-discover>
argument: <>
used: -1
load once: yes
properties:
    module.author = "João Paulo Rechi Vita"
    module.description = "Detect available BlueZ 5 Bluetooth audio devices and load BlueZ 5 Bluetooth audio drivers"
    module.version = "10.0"
...

As a final output it would be nice to have something like this:

index: N
name: <module-cli-protocol-unix> 
argument: <not-empty-value> 

According to the exact input example the sorted output should be as:

    index: 9
    name: <module-cli-protocol-unix> 
    argument: <sink_name=module-cli_>

...but the solution should be dynamic in case another module with non-empty args is about to be init-ed...

So my question is how to make grep output name if argument has non-empty value? And, yes, it would be nice to have a non-script solution... ;).


EDIT

I just tried the solution as pacmd list-modules | grep -B2 'argument: <[^>]' | grep -Po 'index:.*|name: <module-cli-protocol-unix>' but the output is following:

index: 0
index: 1
name: <module-cli-protocol-unix>
index: 25
index: 26
name: <module-cli-protocol-unix>

...which is odd cause it gives 4 index-es for 2 modules but it must have one index per module :S

closed as unclear what you're asking by roaima, Mr Shunz, Scott, Thomas, Haxiel Mar 7 at 18:50

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 7
    Please provide an example of source data, so we can try out your commands against a known input. – roaima Feb 23 at 0:20
  • @roaima you mean the result output? The full output is the pulseaudio's $pacmd list-modules – user390525 Feb 23 at 0:28
  • This is conjecture at best, but I suspect you are after $pacmd list-modules | grep -e 'name: <module-cli-protocol-unix>' | grep -e 'argument: – iruvar Feb 23 at 3:53
  • @iruvar in this case the argument also outputs as argument: <> if it is empty so how to skip if there is argument: <> also output expected? – user390525 Feb 24 at 2:48
  • @user390525 To be able to test solutions to this issue, we would need to know what the input to grep might look like, and we also (for clarity) need to know what you expect to get as the result under different conditions. I have voted to close this question as "unclear" until such information is added. – Kusalananda Feb 24 at 10:26
1
pacmd list-modules |\
grep -B2 'argument: <[^>]' |\
grep -B1 -A1 'name: <module-cli-protocol-unix>'
  • The -B option prints lines before a match as well as the match itself
  • the -A option prints lines after a match
  • if whitespace is a problem, it can be stripped with sed, for example

So the process is:

  • list all the modules
  • filter on non-zero arguments
  • then filter on the corect module name
  • Thank you for your reply. Is there a way to have -e 'index: ' which is related to the selected module? I just tried pacmd list-modules | grep -v 'argument: <>' | grep -e 'name: <module-cli-protocol-unix>' -e 'index: ' but seems like it outputs all existing modules index-es instead of the found one :P – user390525 Feb 25 at 4:02
  • read the grep documentation on the meaning of -B and -v – jhnc Feb 25 at 4:06
  • 2
    pacmd list-modules | grep -B2 'argument: <[^>]' | grep -B1 name: <module-cli-protocol-unix>' – jhnc Feb 25 at 4:09
  • I just edited my question please see it. – user390525 Feb 25 at 4:20
  • See my amended comment – jhnc Feb 25 at 4:26
0

It will be unclear until you provide some sample, but you can try:

pacmd list-modules | grep -v 'argument: <>' | grep -e 'name: <module-cli-protocol-unix>'

It will first reject all strings having empty values for argument and then will only grep those lines which have name: <module-cli-protocol-unix>.

  • Thank you. Seems like it is very nearby the point. I also tried to include index with the expression pacmd list-modules | grep -v 'argument: <>' | grep -e 'name: <module-cli-protocol-unix>' -e 'index: ' but it outputs all modules index-es not the found ones :( – user390525 Feb 25 at 4:13
  • @user390525 you can use one more pipe and then use grep -e 'index: '. – Prvt_Yadv Feb 25 at 8:46
0

If you are considering argument: <> to be an empty argument then this could work

pacmd list-modules | grep -B2 '^argument: <..*>' | grep -E '^(index|name|argument):'

Output from sample:

index: 9
name: <module-cli-protocol-unix>
argument: <sink_name=module-cli_>
  • what grep version do you use? I have v3.0 now installed. – user390525 Mar 3 at 16:00
  • No, I want the argument to be NOT EMPTY; I mean it should have values like a argument: <some_param=value etc> – user390525 Mar 3 at 16:03
  • SO GIVE SOME EXAMPLES SO WE DONT HAVE TO KEEP GUESSING – roaima Mar 3 at 16:53
  • OK. I edited my question adding comments to the exact input source the module(s) which is about to be extracted; But the final solution should be dynamic in case a similar module is about to be init-ed... – user390525 Mar 3 at 17:24
-1

Tried with below command and worked fine

command

pacmd list-modules|awk '/index: [0-9]/||/name: <.*>/||/argument: <.*?>/{print $0}' 
  • Thank you for your reply. I am not sure how to integrate the solution if to use the $pacmd list-modules utility command instead of the filename? – user390525 Mar 2 at 18:35
  • I am not sure how to convert it to grep? Could you provide the solution with grep util? – user390525 Mar 3 at 15:58
  • KIndly check edited posted – Praveen Kumar BS Mar 3 at 15:59
  • The output I have in this case is index: 5 name: <module-cli-protocol-unix> argument: <> index: 6 name: <module-switch-on-port-available> argument: <> index: 7 name: <module-udev-detect> argument: <> index: 8 name: <module-bluetooth-policy> argument: <> index: 9 name: <module-bluetooth-discover> argument: <> index: 10 name: <module-cli-protocol-unix> argument: <sink_name=module-cli_> – user390525 Mar 3 at 16:23
  • Thank you. It is very interesting; But it doesn't extract the module-cli-protocol-unix params only :P According to the input format I give in my question the output at lease must have one module cause there are only one module-cli-protocol-unix module has non-empty argument but still the solution must be dynamic in case some new particular modules may be init-ed – user390525 Mar 3 at 16:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.