Skip to content

Instantly share code, notes, and snippets.

@andras-tim
Last active April 11, 2017 12:29
Show Gist options
  • Save andras-tim/6143769fa2afc83e253d19e0d30b6bd2 to your computer and use it in GitHub Desktop.
Save andras-tim/6143769fa2afc83e253d19e0d30b6bd2 to your computer and use it in GitHub Desktop.
How can I filter STDIN by globbing in bash?

http://stackoverflow.com/q/43344791/1108919

Problem

I want to rewrite filter_script.sh to accepts globbing patter only instead of regexp (current working)

Expected

Test

echo -e 'apple tree\nbanana tree\norange tree' | ./filter_script.sh '*ban' '*ge*'

Output:

banana tree
orange tree
#!/bin/bash
set -eufo pipefail
exclude_args=()
for exclude in "$@"; do
exclude_args+=(-e "${exclude}")
done
grep -x "${exclude_args[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment