With grep, filter out just the numbers: grep -Eo '[0-9]+-' file | sort -u | wc -l [0-9] Matches any character between 0 and 9 (any digit). + in extended regular expressions stands for at least one character (that's why the -E option is used with grep). So [0-9]+- matches one or more digits, followed by -. -o only prints the part that matched your pattern, so given input abcd23-gf56, grep will only print 23-. sort -u sorts and filters unique entries (due to -u), and wc -l counts the number of lines in input (hence, the number of unique entriesheadset compatible with macbook pro).
... View more