#!/bin/sh while read i; do echo "$i"|sed 's#-[^-]*-[^-]*-[^-]*$##' done < $1 > bof sort bof > ${1}_short rm bof