Using some tools like grep, sed, awk, & sort you can implement some answers from this other site. They include (if you wanted b then d then everything else normally):
Pull out lines in the order desired, starting with the first, then second, etc"
grep '^b' myfile > outfile grep '^d' myfile >> outfile grep -v '^b' myfile | grep -v '^d' | sort >> outfile
Add your custom "sort key" first, then sort, then remove it later:
sed -e 's/^b/0&/' -e t -e 's/^d/1&/' -e 't' -e 's/^/2/' | sort | sed 's/^.//'
The easiest looks to be:
use a language such as Perl, Python or Ruby that lets you easily specify a custom sort function.
perl -e 'print sort {($b =~ /^[bd]/) - ($a =~ /^[bd]/) || $a cmp $b} <>' python -c 'import sys; sys.stdout.write(sorted(sys.stdin.readlines(), key=lambda s: (0 if s[0]=="b" else 1 if s[0]=="d" else 2), s))'
Or try awk (no explanation given, YMMV):
sort myfile | awk '$0 ~ /^b/ || $0 ~ /^d/ $0 !~ /^b/ && $0 !~ /^d/ { a[f++] = $0 } END { for (word = 0; word < f; word++) { print a[word] } }'