[mdlug] How to find file name length?

Raymond McLaughlin driveray at ameritech.net
Fri Sep 28 01:19:03 EDT 2007


Aaron Kulkis wrote:
> Raymond McLaughlin wrote:

>> Oh? I tested the egrep statement thus:
>> pts/1 $ for ((i=1; i<216; ++i)); do echo $i; done | \
>>  egrep '[0-9]{3,}'
>> 100
>> 101
>> 102
>> 103
>> 104
>> 105
>> <snip>
>> 212
>> 213
>> 214
>> 215
>>
>> How are 100-103 excluded?
>>
>> Also did any one notice that the "echo "$(basename "{}" | wc -c" part
>> doesn't work as intended? Observe:
>>
>>     echo filename.txt | wc -c
>>     13
>>
>> wc counts the trailing new line as a character, you need to use "echo -n"
>>
>>     echo -n filename.txt | wc -c
>>     12
>>   
> 
> 
> Good work, Ray

Thanks Aaron. Too bad (in the first part) I had sort of missed the point
of the comment I was replying to. I.e.that 100-104 character filenames
are acceptable and thus should not be included in what is intended as a
list of "bad" filenames.

At the end of the day all this would only lead to generation of a list
of files to be presented to a human for final scrutiny and action. It
would be very ticklish trying to script *how* overly long filenames
should be shortened.





More information about the mdlug mailing list