[英]How can I operate on successive files using ls and xargs?
我有一个充满文件的文件夹,其中:
ls *101* | grep -v "discard"
给我这个:
test101v1.nc
test101v2.nc
test101v3.nc
现在,我需要连接这些文件,通常我可以使用以下文件进行连接:
ncrcat test101v1.nc test101v2.nc test101v3.nc out.nc
如何在shell脚本中使用xargs
来做到这一点?
我可以使用for循环,但是我想知道是否可以通过更智能的方式来完成?
为什么要使用xargs? 怎么了
ls *101* | grep -v "discard" | ncrcat -o out.nc
试试ls *101* | grep "discard" | xargs ncrcat -o out.nc
ls *101* | grep "discard" | xargs ncrcat -o out.nc
或者您可以使用命令find:
find . -type f \\( -name "*101" ! -name "*discard*" \\) | xargs ncrcat -o out.nc
另一种使用数组的方式如下: ncrcat $(ls *101* | grep "discard") -o out.nc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.