mitochondrion
mitochondrion

Reputation: 61

How can I print the name of each file that is being assessed in a for loop (linux)

I'm not quite sure how to print the file name being processed from within a for loop in linux. I realize that similar questions have been asked, but I haven't successfully adapted any of the suggested responses yet.

I'm trying to entries in a file and output the file name. Each individual entry is made up of 4 lines, which is the reason that I’m dividing by 4. I can easily count the entries via:

for i in *.gz; do expr $(cat $i | wc -l) / 4; done

But how can I output the filename?

Thanks for your help! Ryan

Upvotes: 0

Views: 29

Answers (1)

tink
tink

Reputation: 15204

Does this help?

for i in *.gz
do 
  echo "$i"
  expr $(cat "$i" | wc -l) / 4
done

Upvotes: 1

Related Questions