I am sort of new to unix and I am having difficulty sorting. What I am trying to do is sort a particular field in reversed order and another field in alphabetic order to create a new file that looks like this:
MILLER,EDWARD AL 14 101293 9341
MOORE,HENRY 15 101297 9077
NGUYEN,LE HUU 13 101314 9576
*NOTE THAT THE SPACINGS ARE NOT DISPLAYED CORRECTLY; IT SHOULD BE ALL LINED UP
Basically, "+0.20 -0.24" represents the first two digit numbers that needs to be reversed and "+0.00 -0.16" represents the names that needs to be in alphabetic order.
why don't you use sort -k to specify the field and -t as field seperator
this is just an example..
Quote:
sort -t: +1 -2 -n +0 -1 -r filename
This command sequence performs a numeric sort on the second field (+1 -2 -n). Within that ordering, it sorts the first field in reverse alphabetic order (+0 -1 -r)
I could not specify the field for the two digit numbers because the names are not homogeneous. What I mean by that is that some of the names have 1 field and some of them have 2 fields:
You can see from above that the first and third name have 2 fields because of the middle name initials separated from the full names by a space. So, for those names, to get to the two digit numbers, you have to specify the 3rd field but for the name in the middle, you only have to specify up to the 2nd field.
So, what I did was count the spaces and use columns to specify the two digit numbers and reversed them. Next, I used the -k option to specify the 1st field for the names in alphabetic order using -d (sort in "phone directory" order). And it made my day! Took me so long to figure that one out and your replies really helped me understood how the whole thing works. Thanks for your help!
Last edited by Perderabo; 09-21-2008 at 05:32 PM..
Reason: Add code tags for readability
I need to work with records having #AX in the EXP1 , please see my data sample and my attempt below:
$ cat xx
08:30:33 KEY1 (1255) EXP1 VAL:20AX0030006
08:30:33 KEY1 (1255) EXP1 VAL:20AX0030006
08:30:33 KEY1 (1255) EXP1 VAL:20AW0030006
08:30:33 KEY1 (1255) EXP1 VAL:20AW0030006
$ gawk '{... (1 Reply)
Hi ,
I trying to cp a files to one location and trying to untar there,the tar.gz files get copied to the specified location but wont untar. Here is what i did
if cp /path/of/the/file.tar.gz /path/to/the/file/file.tar.gz
then
tar -zxvf /path/to/the/file/file.tar.gz
echo "FILE... (2 Replies)
Dear All
I have having some trouble with pam_tally2 on RHEL 6.0 which I am getting quite frustrated with and I am sure it is a simple problem.
I have the following lines in system-auth and password-auth: -
auth required pam_tally2.so onerr=fail file=/var/log/faillog... (1 Reply)
i have list of files:
Wang De Wong CVPR 09.pdf
Yaacob AFGR 99 Second edition.pdf
Shimon CVPR 01.pdf
Den CCC 97 long one.pdf
Ronald De Bour CSPP 04.pdf
.....
how can i sort this directory so the output will be in the next format:
<year>\t<conference/journal>\t<author list> - t is tab
(its... (1 Reply)
how can i sort the next list just by look at the numbers (ignore letters)
example:
abc123
dff4f
aaa2aa
bbbb55555bb
output:
aaa2aa
dff4f
abc123
bbbb55555bb (1 Reply)
I am trying to set up iscsi linux clients and am having some problems. iscsid is running, I can do discovery fine, but adding the iscsi lun I get the following error: iscsiadm -m node -T iqn.xxxxxxxxxxxxxx -p y.y.y.y:3260 -l Logging in to iscsid: session already running. iscsiadm: Could not... (0 Replies)
The data we are searching is populated in this way:
----IP---------DAY----MONTH----DATE--------TIME---------YEAR
12.3234.34-----Fri------Nov-------15-------18:05:14 GMT---2008
I want the user to be able to search for the data according to month and year.
However, I cannot quite figure out... (8 Replies)
Hi ....
iam having a file with 20,000 rows and 56 colums.
Iam trying to sort a file ....for that iam using 'sort' command.
If iam having 3 and 5 key colums etc ... as numerical this 'sort' command will work? what ihave to do ?
sample example :
E100|0|19940102|1|11111|E003... (3 Replies)
I'm trying to write 2 programs, client & server, that communicate with integers, however, all resources I have found on the net assume that you want to send and recieve information as a character array. I don't want to send my integers as characters, I want to send them as ints (casting them to... (2 Replies)