LoginSignup
12
18

More than 5 years have passed since last update.

shell: lsの結果をforで処理する

Posted at

lsの結果をforで処理する方法。
grepで特定の拡張子に限定してから処理することも可能。

例)指定のディレクトリ内のすべてのtxtファイルの行数を表示する

for txt in $( ls . | grep .txt$ ); do   
    echo ${txt}  `cat $txt | wc -l`
done
12
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
18