shell - If xargs is map, what is filter? -


I find xargs as the map function of Unix open. What is the filter function?

EDIT: It seems that I have to be a bit more clear.

Let me assume that a program that accepts a string as a parameter and returns with the exit code of 0 or 1. This program will act as a verdict on those wires that accept it.

For example, I can choose to interpret the string parameter as a file path, and defines "to present this file" in this situation, in this case, the program < Code> test -f , which is given the string, if the file exists, and 1 otherwise exits 1.

For me, even for a section of a wire example, I can have a file containing ~ / path /

  / etc / apache2 /apache2.conf / foo / bar / baz / etc / hosts  

Now, I would like to create a new file, ~ / existing_text , in which only on my path In my case, it will be

  /etc/apache2/apache2.conf/ etc / hosts  

I have it ~ / path Define those lines, type test -f , and output to ~ / existing_paths . In accordance with xargs , it will look like this:

  cat ~ / path | Xfilter test -f> ~ / Current_paths  

This hypothesized program is xfilter that I want to:

  xfilter COMMAND [ARG] ...  

For every line of its standard input, L will call COMMAND [ARG] ... L , And if the exit code is 0, it prints L , and it does not print anything.

To be clear, I'm not looking for:

  • A way to filter the list of filespace from existence. This was a typical example.
  • How can I do such a program?

I am either:

  • A pre-existing implementation, such as xargs text > If the map is xargs , then filter still xargs .

    Example: List files in existing directories and filters outside non executable files:

      ls | Exercise-Eye {} Sh-C "Test-X '{}' & amp; amp; & amp; echo '{}'"  

    This can be made easy trough (non Output-ready) Function:

      xfilter () {xargs -i {} sh -c "$ * '{}' & amp; amp; esco '{}'"} ls | Xfilter test -x  

    Alternatively, you can use a parallel filter implementation via GNU parallel:

      ls | Parallel "test -x '{}' & amp; echo '{}'"  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -