How to process every second file in bash?

后端 未结 4 1264
忘掉有多难
忘掉有多难 2021-02-15 23:55

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 thi

4条回答
  •  被撕碎了的回忆
    2021-02-16 00:22

    for file in `find dir -type f | awk 'NR % 2 == 0'`; do
      echo $file
    done
    

    NR is the current row number. To get odd rows, use ... == 1.

提交回复
热议问题