Since I learned some bash syntax, I have being very enthusiastic about its use in daily life. A famous command is grep
. In case one with to grep something but ignore several files, the commands below MAY work.
grep_ignore=("token_a", "token_b")
grep -rnw . -e "token2" | grep -v <(printf '%s
' "${grep_ignore[@]}")
How to reproduce:
Create some dummy folder: command run
mkdir dummy & cd dummy
Create files:
a.
file_token_a.txt
: command runecho "token1 token2" > file_token_a.txt
;
b.
file_token_b.txt
: command runecho "token1 token3" > file_token_b.txt
c.
file_token_c.txt
: command runecho "token2 token3" > file_token_c.txt
Command run:
grep_ignore=("token_a", "token_b")
grep -rnw . -e "token2" | grep -v <(printf '%s
' "${grep_ignore[@]}")
Expected output:
./file_token_c.txt:1:token2 token3
Given output:
./file_token_c.txt:1:token2 token3
./file_token_a.txt:1:token1 token2