Sorting data from a to z


 
Thread Tools Search this Thread
# 1  
Sorting data from a to z

Hi,

Let's say I have these 3 columns;

Code:
NGC1234  6  9
SL899      4  1
NGC1075   8  3
SL709      5  2

And I want to sort the data according to the first column (from a to z) like having them as:

Code:
NGC1075   8  3
NGC1234  6  9
SL709      5  2
SL899      4  1



Can that be done using AWK?

Last edited by vgersh99; 08-12-2009 at 05:00 PM.. Reason: code tags, PLEASE!
# 2  
Using awk, I don't know, but you can use sort instead
I created a file named test1 for this example:
Code:
$ cat test1
NGC1234 6 9
SL899 4 1
NGC1075 8 3
SL709 5 2
$ sort test1
NGC1075 8 3
NGC1234 6 9
SL709 5 2
SL899 4 1
$

You can also use sort after a pipe:
Code:
$ awk '{print}' test1 | sort
$ cat test1 | sort


Last edited by tukuyomi; 08-12-2009 at 05:01 PM..
# 3  
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Sorting the Data
ckaramsetty
My actual data looks like below i have given only format. i can't give exact data format of my requirement due to some reasons. I this set of data lines about 5000 I need to come up with information in below exact format of my data set : Line<space>Number1<space>"somedata":...... Shell Programming and Scripting
1
Shell Programming and Scripting
Help with Data Sorting
pawannoel
Hi All, I have a long list made of 4 columns containing entries such as the following example: a b c d 0 0 0 0 1 2 1 2 2 5 3 4 3 8 4 6 4 10 9 8 5 15 8 10So the top row is the header and I need to arrange the data in a way as to...... UNIX for Dummies Questions & Answers
11
UNIX for Dummies Questions & Answers
Sorting data
visuelz
Hello guys. I need help figuring this one out. It's probably really easy. Thanks in advance! I have a file say for example containing this: Rice Food Carrots Food Beans Food Plates Kitchen Fork Kitchen Knives Kitchen I need: Food Rice, Carrots, Beans Kitchen Plates, Fork,...... UNIX for Dummies Questions & Answers
7
UNIX for Dummies Questions & Answers
PERL data - sorting
eagercyber
Hello, I have a page where multiple fields and their values are displayed. But I am able to sort only a few fields. When I looked into the issue, it is seen that the for each row of info , an unique id is generated and id.txt is generated and saved. Only those fields which are inside that id.txt...... Shell Programming and Scripting
3
Shell Programming and Scripting
sorting data from who by IP
raidzero
Hello. I have an RS/6000 running AIX 4 and I need to be able to see if there are any users that are logged on more than once from the same terminal so I can kick them off to make room for other terminals. 64 connections is the limit. Currently I am doing this: who | more and then manually...... UNIX for Dummies Questions & Answers
11
UNIX for Dummies Questions & Answers

Featured Tech Videos