UNIX find 用于查找未配对的文件名
是否有一种简单的方法可以递归地查找目录层次结构中没有具有不同扩展名的匹配文件的所有文件?
例如,该目录有一堆以 .dat 结尾的文件,
我想找到没有附带 .out 文件的 .dat 文件。
我有一个 while 循环来检查每个条目,但这对于长列表来说很慢......
我正在使用 GNU find。
Is there a simple way to recursively find all files in a directory hierarchy, that do not have a matching file with a different extension?
For example the directory has a bunch of files ending in .dat
I want to find the .dat files that do not have an accompanying .out file.
I have a while loop that checks each entry, but that is slow for long lists...
I am using GNU find.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许是这样的?
我还没有测试过,但我认为它可能接近你的要求。
Perhaps something like this?
I haven't tested it, but I think it's probably close to what you're asking for.
我不得不在第一个解决方案中添加一堆花哨的东西,但这是一个好的开始,谢谢...
find 。 -打印| grep -Fi '.dat' | grep -Fi '.dat' | grep -vFi '.dat'。 |排序| sed -e 's/.dat //g' >列1.txt
寻找 。 -打印| grep -Fi '.out' | grep -Fi '.out' | grep -Fi '.out' | grep -Fi '.out' grep -vFi '.out'。 |排序| sed -e 's/.out //g' >列2.txt
sdiff -s 列1.txt 列2.txt | grep -F '<' |剪切-f1-d“<” > c12diff.txt
I had to add a bunch of bells and whistles to the 1st solution, but that was a good start, thanks...
find . -print | grep -Fi '.dat' | grep -vFi '.dat.' | sort | sed -e 's/.dat//g' > column1.txt
find . -print | grep -Fi '.out' | grep -vFi '.out.' | sort | sed -e 's/.out//g' > column2.txt
sdiff -s column1.txt column2.txt | grep -F '<' | cut -f1 -d"<" > c12diff.txt