bash - 如何对查找结果进行排序,以使以一组模式之一开头的路径排在最后

标签 bash sorting makefile find etag

我有一个 find 命令,我想对其进行排序,以便某些目录的条目最后排序。原因是这个列表要传递给 etags 以创建标签表,并且我希望某些第三方工具目录位于我主动编辑的所有代码之后。

有人可以建议一种简单的方法来对列表进行排序作为对我的 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 命令放入大括号 block 中,并将其通过管道传输到 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

关于bash - 如何对查找结果进行排序,以使以一组模式之一开头的路径排在最后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3697457/

相关文章:

sql-server - 如何使用脚本在Docker中创建数据库和用户?

c++ - 将文件添加到 Netbeans C++ 项目

makefile - 用于构建库的旧 Makefile 在 FreeBSD 下不再工作

bash - 在 BASH 脚本中存储文件

linux - 哪个配置文件将登录密码原始文本转换为 Linux 中的哈希值?

bash - Shell函数是否在子shell中运行?

makefile - 规范 'simple project' 生成文件

java - java 按索引排序

Javascript 带条件排序给出乱序结果

algorithm - 找到尽可能多次与多边形相交的射线