I have two variables, one with text, and another with patterns. And I want to filter out lines, matched patterns. How can I do that?
My script looks like this
# get ignore files list
IGNORE=`cat ignore.txt`
# get changed files list
CHANGED=`git diff --name-only $LAST_COMMIT HEAD`
# remove files, that should be ignored from change list
for IG in $IGNORE; do
echo $CHANGED
$CHANGED=`cat $CHANGED | grep -v $IG`
done
You can supply the pattern file directly to grep
# get changed files list and remove files that should be ignored
CHANGED=$(git diff --name-only $LAST_COMMIT HEAD | grep -vf ignore.txt)
echo $CHANGED
(I recommend using $() instead of backticks.)
By the way, this line:
$CHANGED=`cat $CHANGED | grep -v $IG`
should probably look like this:
CHANGED=`echo $CHANGED | grep -v $IG`
if you were going to keep it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With