我有这条线:
find -maxdepth 1 -type f -iname '*key*' -not -name '*~'
我想提取所有返回文件的内容(应该是文本)并将其通过管道传输到 sort
中以按字母顺序排序。我已经尝试将上述行的输出直接传送到 sort
中,但这会导致文件名而不是它们的内容被排序。我是否需要将 find
的输出转换为一个数组,然后通过 sort
对其进行处理?
[edit] 我想要的输出是排序后的内容。
最佳答案
为了完整起见,这里还有几种方法:
find -maxdepth 1 -type f -iname '*key*' -not -name '*~' -exec cat {}\; |排序
find -maxdepth 1 -type f -iname '*key*' -not -name '*~' | xargs 猫 |排序
cat $(find -maxdepth 1 -type f -iname '*key*' -not -name '*~') |排序
关于Bash:按内容对 'find' 中的文件进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18158365/