如何对找到结果进行排序,以使以一组模式开始的路径进行了排序
题
我有一个我想整理的查找命令,以使某些目录的条目最后对。原因是该列表应传递给ETAG来创建标签表,我希望某些第三方工具目录在我主动编辑的所有代码之后。
有人可以提出一种很好的简便方法,以将清单作为我的Makefile规则的更改进行排序吗?这是当前的规则:
tags:
rm -f ../TAGS
find .. \( -not -regex '.*include/.*' \) \
-a \( -name '*.h' -o -name '*.hh' -o -name '*.y' \
-o -name '*.l' -o -name '*.cc' -o -name '*.cpp' \
-o -name '*.c' -o -name '*.inl' \) \
| xargs etags -o ../TAGS --append
例如,应该在不匹配这些模式之一的条目之后出现开始“ ../flexlm/”或“ ../ src/librsync”的条目。
解决方案
放置多个 find
在支撑块中命令,然后将 xargs
:
# the single quotes take care of the escaping
pattern='( -not -regex ".*include/.*" )
-a ( -name "*.h" -o -name "*.hh" -o -name "*.y"
-o -name "*.l" -o -name "*.cc" -o -name "*.cpp"
-o -name "*.c" -o -name "*.inl" )'
{
find ! -path "../flexlm/*" ! -path "../src/librsync/*" $pattern
find -path "../flexlm/*" $pattern
find -path "../src/librsync/*" $pattern
} | xargs etags -o ../TAGS --append
其他提示
好吧,假设您有能力运行多个查询查询,并且您可以通过一个查询和任何其他查询的任何库来找到自己的项目。
...那将是我要做的。
这是通过结合上述答案并调整它们来对我有用的方法:
PATTERN := \( -not -regex '.*include/.*' \) \
-a \( -name '*.h' -o -name '*.hh' -o -name '*.y' \
-o -name '*.l' -o -name '*.cc' -o -name '*.cpp' \
-o -name '*.c' -o -name '*.inl' \)
.PHONY: tags
tags:
rm -f ../TAGS
find .. \
! -path "../src/librsync/*" \
! -path "../flexlm/*" \
$(PATTERN) | xargs etags -o ../TAGS --append
find .. -path "../src/librsync/*" \
$(PATTERN) | xargs etags -o ../TAGS --append
find .. -path "../flexlm/*" \
$(PATTERN) | xargs etags -o ../TAGS --append
不隶属于 StackOverflow