在 bash 脚本中按模式过滤行
我有两个变量,一个包含文本,另一个包含模式。我想过滤掉线条、匹配的图案。我怎样才能做到这一点?
我的脚本看起来像这样
# 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以直接向 grep 提供模式文件
(我建议使用
$()
而不是反引号。)顺便说一句,这一行:
应该看起来像这样:
如果您要保留它。
You can supply the pattern file directly to grep
(I recommend using
$()
instead of backticks.)By the way, this line:
should probably look like this:
if you were going to keep it.