[plug] Find similarly named files in directories

Bernard Blackham bernard at blackham.com.au
Sat Jan 13 11:52:03 WST 2007


Carl Gherardi wrote:
> On 1/12/07, Timothy White <weirdit at gmail.com> wrote:
>> Ok, so 2 simple sed's and I solve the space problem!! Not sure if
>> there are any other "bugs"
>>
>> find| sed 's/\ /:::/g' |sed -r 's/.*\/(.*)/\0 \1/'|sort -i -k 2|uniq
>> -i --all-repeated=separate -f 1| sed 's/[^ ]*$//' | sed 's/:::/\ /g'
>>
>> Rather simple, first check no file name as 3 :'s in a row, if it does,
>> find another "uniq" sequence to replace it with.
> 
> Was a challenge for golf originally an i'm bored. 138 chars is benchmark.

Gah, I'll bite. 59 chars of perl, 74 chars altogether.

find|perl -ne'm#.*(/.*)#;push@{$a{$1}},$_}foreach(%a){$#$_>0&&print"@$_\n"'

And the only thing it'll break on is files with new-lines in them (yes, 
it's possible! The only things you can be guaranteed not to find in a 
filename are / and the NULL byte).

It's an extra 2 chars for the case-insensitive version too ;)

I feel it could be a little shorter, but I can't see how at the moment.

Bernard.



More information about the plug mailing list