Question is simple, but I can’t find a fast and elegant way to solve.
I want to decide next: if block size of files is more than 6 then I should print filenames.
stat a.txt b.txt | awk '/Blocks/ {print $4} /File/ {print $2}'
This code returns
'a.txt' 3 'b.txt' 10
But if I use NR==... it cuts row with filename.
Advertisement
Answer
You can format the output of stat to make processing easier (requiring GNU stat):
stat -c '%b %n' a.txt b.txt | awk '$1 > 6 {print $2}'
where (excerpts from man page)
%bnumber of blocks allocated
%nfile name
Or, if your filenames contain special characters, you can get them to be printed with quotes:
stat -c '%b %N'
where
%Nquoted file name with dereference if symbolic link