views:

20

answers:

1

I have a directory with multiple files in the form of:

file001_a
file002_a
file002_b
file003_a

Using a shell script, I was wondering what the easiest way would be to list all files within this directory that have duplicates in the first 7 letters; ie the output above would be:

file002_a
file002_b

any help would be much appreciated!

+3  A: 
ls -1 *_*| awk '{fn=substr($0,1,7);a[fn]=a[fn]" "substr($0,8)}END{for(i in a) print i,a[i]}'
ghostdog74
it hurts my eyes, but does everything i want it to do - thank you! :)
JT.WK