0
I want something like this:
find "$dir" -type f -printf '%i:<alpha_char_count_of_base_filename>:%d:%p\n'
Then I want to sort first on inode number, then on alpha_char_count_of_base_filename. I think I have part of the solution figured out.
I know I can get the alpha_char_count_of_base_filename with this code:
basename "$filename" | tr -cd [:alpha:] | wc -m
However, trying something like this (don't laugh) doesn't work:
find "$dir" -type f -printf '%i:$(basename -print | tr -cd [:alpha:] | wc -m):%d:%p\n'
I've tried a lot of ideas and I have not lucked onto a working solution. Here's another idea I tried:
find "$dir" -type f -printf '%i:%d:%p\n' | awk 'BEGIN{FS=":";OFS=":";} {print $1,system("basename "$3" | tr -cd [:alpha:] | wc -m"),$2,$3"\n";}'
This seems to be getting me closer, but it prints the alpha_char_count_of_base_filename in the wrong location. I'm also not confident that is is good programming form.
My shell programming book doesn't offer me anything that would help me come up with a solution to this specific question. Neither does Google (so far).
This will be used as a solution to this question.
Thanks! The only issue is I'm getting the alpha count of the entire path instead of the desired basename (filename alone). – MountainX – 2012-03-29T19:30:40.273
I think I can live with this. Thank you. I'll accept this answer if a basename answer doesn't come along. – MountainX – 2012-03-29T20:04:33.510
@MountainX, updated my answer to only use the basename -- it uses the
%f
formatting specifier to send the basename to awk where it gets replaced with the "alpha length" – glenn jackman – 2012-03-29T20:11:49.320