如何处理在bash每秒文件? [英] How to process every second file in bash?

查看:110
本文介绍了如何处理在bash每秒文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个几十文件的目录。我想做点什么从这个目录中的每个第二个文件。现在我只用找到命令,但这个我处理所有的文件:

 找到./dir/型的F -exec猫{} \\;


解决方案

  CNT = 0;
在$文件(找到./dir型的F); < - 如果没有太多的比赛

  让CNT = CNT + 1;
  如果[$ CNT -eq 2];
    然后回声$文件; < - 做一些事情
    CNT = 0; < - 备用文件
  网络连接;
DONE

  second_file = $(找到型F |头-2 |尾-1);

I have a directory with a few dozens of files. I would like to do something with every second file from this directory. By now I only used find command but with this I process all files:

find ./dir/ -type f -exec cat {} \;

解决方案

cnt=0; 
for file in $(find ./dir -type f); <-- if not too many matches
do 
  let cnt=cnt+1; 
  if [ $cnt -eq 2 ]; 
    then echo $file;               <-- do something
    cnt=0;                         <-- alternate file
  fi; 
done

or

second_file=$(find -type f | head -2 | tail -1);

这篇关于如何处理在bash每秒文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆