Sort (bash command)

I did a search on this, and found lots on SORT but no answer to my question.

I have a C program that fetches all of our users from Netware, and I have that it makes a file that I later include in a html as a select tag drop-down menu.

Here is what 1 line looks like:
<option value="fname.lname">Lname, Fname (CSC)</option>

I have roughly 600 lines (teachers) in about 40 schools (school codes [CSC])

my question concerns the bash command �sort�
the (CSC) is a code pointing to a school, I want to first sort by the school code, then sort by name within that code, and do this for every code. Is this possible using the bash command �sort�. I read this page sort Man Page - Linux - SS64.com and I don't think it's possible but I would like a second opinion.

thanks

I am not very sure about you requirement but see whether this helps:

$ cat sorttest
<option value="abhishek.ghose">ghose, abhishek (CSC)</option>
<option value="booboo.b">b, booboo (CSC)</option>
<option value="arvind.kumar">kumar, arvind (KLL)</option>
<option value="r.garg">garg, r (AKLL)</option>

$ awk -F"\"" '{print $2""$0}' sorttest|awk -F"[()]" '{print $2$0}'|sort -t''
-k 1|awk -F"*" '{print $2}'

<option value="r.garg">garg, r (AKLL)</option>
<option value="abhishek.ghose">ghose, abhishek (CSC)</option>
<option value="booboo.b">b, booboo (CSC)</option>
<option value="arvind.kumar">kumar, arvind (KLL)</option>

Abhishek

heres a shorter version:

awk -F"[\"()]" '{print $4$2""$0}' sorttest|sort -t'' -k 1|awk -F"*" '{print
$2}'

Achieves the same result as bfore, but lesser said....

I'm going to digest this and let you know how I do.

thanks guys :slight_smile:

yep... works great.

thanks Abhishek...
I would've been on this for a long time now that I see the solution.

thanks again, very much appreciated :smiley:

ruby -e 'puts $<.sort_by{|x| x.split( /["()]/ ).values_at(3,1) }'