Visit The New, Modern Unix Linux Community

Sort (bash command)

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort (bash command)
# 1  
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 and I don't think it's possible but I would like a second opinion.

# 2  
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>

# 3  
heres a shorter version:

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

Achieves the same result as bfore, but lesser said....
# 4  
I'm going to digest this and let you know how I do.

thanks guys Smilie
# 5  
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 Smilie
# 6  
ruby -e 'puts $<.sort_by{|x| x.split( /["()]/ ).values_at(3,1) }'

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #125
Difficulty: Easy
UNIX is a certification of a complete OS system, not only a UNIX kernel.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to sort file with certain criteria (bash)?

I am running a command that is part of a script and this is what I am getting when it is sorted by the command: command: ls /tmp/test/*NDMP*.z /tmp/test/CARS-GOLD-NET_CHROMJOB-01-XZ-ARCHIVE-NDMP.z /tmp/test/CARS-GOLD-NET_CHROMJOB-01-XZ-NDMP.z... (2 Replies)
Discussion started by: newbie2010
2 Replies

2. Shell Programming and Scripting

How do i sort lines lexigraphical in bash?

I am currently having some problems with my script not sorting my files lexiographically. The error seem to be localized here where i sort the utt2spk file, which is done like this.. for x in test train; do for f in text utt2spk; do sort data/$x/$f -o... (7 Replies)
Discussion started by: kidi
7 Replies

3. UNIX for Dummies Questions & Answers

Bash script to sort files

I've got a disorganized list of items and quantities for each. I've been using a combination of grep and sort to find out how much to buy of each item. I'm tired of having to constantly using these commands so I've been trying to write a shell script to make it easier, but I can't figure out how... (3 Replies)
Discussion started by: PTcharger
3 Replies

4. Shell Programming and Scripting

Bash - remove duplicates without sort

I need to use bash to remove duplicates without using sort first. I can not use: cat file | sort | uniq But when I use only cat file | uniq some duplicates are not removed. (4 Replies)
Discussion started by: locoroco
4 Replies

5. Shell Programming and Scripting

BASH: Sort four lines based on first line

I am in the process of sorting an AutoHotkey script's contents so as to make it easier for me to find and view its nearly 200 buzzwords (when I forget which one corresponds with what phrase, which I do now and then). About half to two-thirds of the script's key phrases correspond to locations... (7 Replies)
Discussion started by: SilversleevesX
7 Replies

6. Shell Programming and Scripting

Is it Possible to sort a list of hexadecimal numbers using "sort" command?

Hello Everybody :) !!!. i have question in mind, is it possible to sort a list of hexadecimal numbers using "sort" command? (9 Replies)
Discussion started by: Kesavan
9 Replies

7. UNIX for Dummies Questions & Answers

Sort data by the end of each line using BASH.

I am trying to sort data within a text document by the information at the end of each line. Please see below for an example: <Profile_0 Name="Random name 0" Description="This is the description." Category="System" ProfileFlags.DWD="6" ABCD="{FF350E61-4FFF-4600-BFFF-3B27DD4BA746}"/>... (6 Replies)
Discussion started by: Davinator
6 Replies

8. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

9. Shell Programming and Scripting

bash ps; remove the header, sort and reinsert

Hi, I'm ssh'ing into a server using ruby and sending a one-liner to retrieve the output of the 'ps aux' command. So far, this is what I have: ps aux | sort -r -n -k3 | sed -e '1s/^/this is first\n/' | head -n10 With this I can insert a line at position 1, but I would rather extract the... (3 Replies)
Discussion started by: gekeha
3 Replies

10. Shell Programming and Scripting

How to sort decimal values in bash

Hi, I have a list of values from associative array from 0,..till 1.0000. I tried various sort options; sort -g, sort -nr but it still couldnt work. In other words, the numbers are not sorted accordingly. Please help. Thanks. (1 Reply)
Discussion started by: ahjiefreak
1 Replies

Featured Tech Videos