Is there a way to output file's contents using custom patterns?For instance, having a file myfile with following contents:adbc..how would one sort it using following pattern: print lines starting with b first, then print lines starting with d and then print lines in normal alphabetical order, so expected output is:bdac
Sort using custom pattern
sort
You would need to use something more than just the sort command. First grep the b lines, then the d lines and then sort anything without the b or d at the end of that.grep '^b' myfile > outfilegrep '^d' myfile >> outfilegrep -v '^b' myfile | grep -v '^d' | sort >> outfilecat outfilewill result in:bdacThis is assuming that the lines start with the 'pattern' b and d if that is the whole pattern or something inside the line you can leave out the caret (^)A one-line equivalent would be:(grep '^b' myfile ; grep '^d' myfile ; grep -v '^b' myfile | grep -v '^d' | sort)