Sort with UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort with UNIX
# 8  
Old 10-18-2010
Computer

LoL OK then ...

so if we consider
Code:
M[$2]=$7

when the value of $2 takes - for example - the value 5 and then 3

The array looks like this :
when $2=5

the M array is
M[1] = unknown
M[2] = unknown
M[3] = unknown
M[4] = unknown
M[5] = $7
M[6] = unknown
...

and when the
$2=3
the M array is
M[1] = unknown
M[2] = unknown
M[3] = $7
M[4] = unknown
M[5] = $7
M[6] = unknown
...

?

or does it build an array such as :
M[5]=$7
M[3]=$7

So that in a way or another, is has an internal mapping table or whatever, in which it hold the order in which the [n] has been entered, so it start by scanning M[5] before M[3] whereas 3<5 ...

???

So in short :

i takes the values of $2 in the for construct, but awk still manage a mapping with an internal index mapping or whatever, which helps it to keep the order in which the M[$2] value are entered (even if $2 does not have ordered values)

Is that correct ? or should i go to buy another brain ?

Last edited by ctsgnb; 10-18-2010 at 11:32 AM..
# 9  
Old 10-18-2010
After line 1 M["AD0081010180947"] contains the value 1010180950
After line 2 M["AD0081010180947"] contains the value 1010180956
after line 3 M["AD0081010180947"] contains the value 1010181014
after line 4 M["AD0081010180947"] still contains the value 1010181014
after line 5 M["AD0081010180947"] contains the value 1010181014 and M["ED0061010180949"] contains the value 1010180956
etc.
This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 10-18-2010
Quote:
Originally Posted by ctsgnb
[...]
or does it build an array such as :
M[5]=$7
M[3]=$7
Yes,
it's just a sparse associative (keyed by strings) array.

Quote:
So that in a way or another, is has an internal mapping table or whatever, in which it hold the order in which the [n] has been entered, so it start by scanning M[5] before M[3] whereas 3<5 ...

???
Unless you're using WHINY_USERS (a GNU awk undocumented extention), the internal order of the keys cannot be controlled:

Quote:
Originally Posted by manual
The order in which elements of the array are accessed is determined by the internal arrangement of the array elements within awk and cannot be controlled or changed.
This User Gave Thanks to radoulov For This Post:
# 11  
Old 10-18-2010
Simpler if not as resource-sparing: sort all by columns 7 reverse (not unique) pipe sort unique column 2. The sort -u saves the first holder of a key value. If you want a sequential presentation on another column, that is a third sort.

Code:
sort -r +6 -7 your_file | sort -u +1 -2


Last edited by radoulov; 10-18-2010 at 11:47 AM.. Reason: Code tags, please!
These 2 Users Gave Thanks to DGPickett For This Post:
# 12  
Old 10-18-2010
Ok, i think i start to begin to understand ... Smilie

Thank you guys for your help & patience sharing your knowledge !
# 13  
Old 10-18-2010
Thanks to everybody, i can now complete my script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX sort

Hi I have below pattern A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: pens 4 B:Bags 4 A: cells 6 A: jobs 6 Output I need : A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: cells 6 A: jobs 6 ... (7 Replies)
Discussion started by: pkkanduk
7 Replies

2. Shell Programming and Scripting

Issue with Sort in Unix

Hi All, I am trying to sort the below data using sort command. temp.dat H|S1-511091486889|27-Jul-2011 00:00:00 H|S1-511091486823|27-Jul-2011 00:00:00 H|S1-511091486757|27-Jul-2011 00:00:00 L|S1-511091486889|1 L|S1-511091486823|1 L|S1-511091486757|1 sort -t "|" -k2 -k1 temp.dat My... (5 Replies)
Discussion started by: deepaknbk
5 Replies

3. Shell Programming and Scripting

need Unix script to sort

Hi i have a file like this oprvdw vrc002093j.ksh oprvdw vrc002092j.ksh oprvrc vrc045016j.ksh oprvrc vrc055141j.ksh svemietl bdw0231185.sh svemietl bdw0231145.sh and i need a script which dispalys in below format: oprvdw : vrc002093j.ksh vrc002092j.ksh oprvrc :... (0 Replies)
Discussion started by: p_satyambabu
0 Replies

4. UNIX for Dummies Questions & Answers

UNIX sort command

Need some help with the sort command. I have a large file which needs sorted on the third field separated by : and within the third field, I need it sorted by second field or everything after the . An example of my file is here and for example, the first line I need :ROUTER2.SFLDMI: sorted on the... (2 Replies)
Discussion started by: numele
2 Replies

5. UNIX for Dummies Questions & Answers

using Unix sort command

Hi I am having some difficulties with the UNIX sort command. I want to sort one a file that looks like this (file A): tiger 5 6 3 5 2 bear 4 5 2 1 8 lions 9 2 5 3 1 dogs 8 5 3 3 1 acccording to a file that looks like this (file B): dogs lions tiger bear So... (2 Replies)
Discussion started by: phil_heath
2 Replies

6. UNIX for Dummies Questions & Answers

UNIX Sort question

I was trying to check for the sort of some columns (say 1-10) of particular file. Now, by default, the Unix sort uses as a separator whitespace (e.g. if you have 'foo bar' then it separates it into 'foo' and 'bar' to use as keys) Now, I know which particular columns I want to use as the sort... (1 Reply)
Discussion started by: rev.meister
1 Replies

7. UNIX for Dummies Questions & Answers

unix SORT

Hey guys. I am trying to sort a file by account number through UNIX. I have a few things but it seems to sort by account number AND sort everything after the account number. Help please. Thanks (5 Replies)
Discussion started by: ndoggy020
5 Replies

8. Shell Programming and Scripting

SORT order in Unix

I am converting mainframes JCL to be used in shell on a one to one basis... when i use the sort command unix does ascii sort as a result which numbers are first followed by charecters in the Ascending sort ... but themainframes uses the EBCDIC as result gives the charecters followed by numbers in... (5 Replies)
Discussion started by: bourne
5 Replies

9. UNIX for Dummies Questions & Answers

Unix Sort - Limitations

Hi All, I want to sort a flat file which will contain millions of records based on a key/field. For this I want to use unix sort command and before that I want to make sure that unix sort command has any file size limitations. And also please let me know whether I have to change any... (2 Replies)
Discussion started by: chprvkmr
2 Replies

10. UNIX for Advanced & Expert Users

Unix Sort - Alternatives

Hi All, I want to sort a flat file which will contain millions of records based on a key/field. For this I want to use unix sort command and before that I want to make sure that unix sort command has any file size limitations. And also please let me know whether I have to change any... (1 Reply)
Discussion started by: chprvkmr
1 Replies
Login or Register to Ask a Question