sort the org_no & member_type column ascending


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort the org_no & member_type column ascending
# 1  
Old 11-06-2009
sort the org_no & member_type column ascending

I have a FILE1.DAT with the following information

Code:
21111111110001343 000001004OLF-AA029100020091112
21111111110000060 000001004ODL-CH001000020091112
24444444440001416 000001045OLF-AA011800020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330000060 000001039ODL-CH001000020091112
22222222220000780 000001013OLF-AA006500020091112

i want to sort the org_no column ie position 2:10 in ascending eg 111111111 then 222222222 then 333333333 etc.
also i want to sort the member_type column position 28:33 in asc eg:

for the line 4 above after sorting i should get like this
Code:
23333333330001695 000001039OLF-AA030600020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112

This i want in .KSH script, after i do the sort for the above 2 columns from the input FILE1.DAT i should get the out FILE2.DAT like below

Code:
21111111110001343 000001004OLF-AA029100020091112
22222222220000780 000001013OLF-AA006500020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112
24444444440001416 000001045OLF-AA011800020091112

thanks for the help

Last edited by zaxxon; 11-06-2009 at 07:38 AM.. Reason: use code tags please, ty
# 2  
Old 11-06-2009
Quote:
Originally Posted by new2ksh
...
also i want to sort the member_type column position 28:33 in asc eg:

for the line 4 above after sorting i should get like this
Code:
23333333330001695 000001039OLF-AA030600020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112

...
Your output is wrong. If the data is to be sorted by column positions 28 through 33 in ascending order, then for the rows 4 through 6, it would be this:

Code:
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330001695 000001039OLF-AA030600020091112

In any case, the sort command can be used here:

Code:
$
$ cat file1.dat
21111111110001343 000001004OLF-AA029100020091112
21111111110000060 000001004ODL-CH001000020091112
24444444440001416 000001045OLF-AA011800020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330000060 000001039ODL-CH001000020091112
22222222220000780 000001013OLF-AA006500020091112
$
$ sort -k2,10 -k28,33 file1.dat
21111111110000060 000001004ODL-CH001000020091112
21111111110001343 000001004OLF-AA029100020091112
22222222220000780 000001013OLF-AA006500020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330001695 000001039OLF-AA030600020091112
24444444440001416 000001045OLF-AA011800020091112
$
$

tyler_durden
# 3  
Old 11-06-2009
you are right, that was my mistake the position 28 through 33 should be in descending order.

Quote:
Originally Posted by durden_tyler
Your output is wrong. If the data is to be sorted by column positions 28 through 33 in ascending order, then for the rows 4 through 6, it would be this:

Code:
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330001695 000001039OLF-AA030600020091112

In any case, the sort command can be used here:

Code:
$
$ cat file1.dat
21111111110001343 000001004OLF-AA029100020091112
21111111110000060 000001004ODL-CH001000020091112
24444444440001416 000001045OLF-AA011800020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330000060 000001039ODL-CH001000020091112
22222222220000780 000001013OLF-AA006500020091112
$
$ sort -k2,10 -k28,33 file1.dat
21111111110000060 000001004ODL-CH001000020091112
21111111110001343 000001004OLF-AA029100020091112
22222222220000780 000001013OLF-AA006500020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330001695 000001039OLF-AA030600020091112
24444444440001416 000001045OLF-AA011800020091112
$
$

tyler_durden


---------- Post updated at 09:02 AM ---------- Previous update was at 07:05 AM ----------

Can someone please answer my query.
i like to sort the position 2:10 in ascending and position 32:33 in descending and not 28:33 as i mention earlier in my post.

Infile FILE1.DAT is
21111111110001343 000001004OLF-AA029100020091112
21111111110000060 000001004ODL-CH001000020091112
24444444440001416 000001045OLF-AA011800020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330000060 000001039ODL-CH001000020091112
22222222220000780 000001013OLF-AA006500020091112

Outfie FILE2.DAT should be like this
21111111110001343 000001004OLF-AA029100020091112
22222222220000780 000001013OLF-AA006500020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112
24444444440001416 000001045OLF-AA011800020091112


Quote:
Originally Posted by new2ksh
you are right, that was my mistake the position 28 through 33 should be in descending order.
# 4  
Old 11-06-2009
Quote:
Originally Posted by new2ksh
...
i like to sort the position 2:10 in ascending and position 32:33 in descending and not 28:33 as i mention earlier in my post.

Outfie FILE2.DAT should be like this
21111111110001343 000001004OLF-AA029100020091112
22222222220000780 000001013OLF-AA006500020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112
24444444440001416 000001045OLF-AA011800020091112
The requirement still doesn't match the output.
The requirement says 2:10 ascending and then 32:33 descending.
The output shows 2:10 ascending and then 32:33 ascending.

tyler_durden
# 5  
Old 11-06-2009
what matters to me is the OUTFILE FILE2.DAT
I like to have the data in FILE2.DAT is
21111111110001343 000001004OLF-AA029100020091112
22222222220000780 000001013OLF-AA006500020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112
24444444440001416 000001045OLF-AA011800020091112

your code is
Code:
sort -k2,10 -k32,33

working find but the position 32:33 is in not in alphabetical order. eg:
23333333330000111 000001039ODL-SP002000020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330001695 000001039OLF-AA030600020091112

i want to see the record in alphabetical order like below
23333333330001695 000001039OLF-AA030600020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112

Can you please send me the right code both for the position 2:10 and 32:33
Thanks again.

Quote:
Originally Posted by durden_tyler
The requirement still doesn't match the output.
The requirement says 2:10 ascending and then 32:33 descending.
The output shows 2:10 ascending and then 32:33 ascending.

tyler_durden
# 6  
Old 11-06-2009
Quote:
Originally Posted by new2ksh
...
your code is
Code:
sort -k2,10 -k32,33

...
That isn't my code ! My code had 28, which you changed to 32 and expected it to work. Take a look at the series of responses above.

Quote:
...
i want to see the record in alphabetical order like below
23333333330001695 000001039OLF-AA030600020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112

Can you please send me the right code both for the position 2:10 and 32:33
...
Since you haven't mentioned specifically, I shall assume that you want characters 2:10 sorted ascending and then characters 32:33 sorted ascending as well.

Code:
$
$ cat file1.dat
21111111110001343 000001004OLF-AA029100020091112
21111111110000060 000001004ODL-CH001000020091112
24444444440001416 000001045OLF-AA011800020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330000060 000001039ODL-CH001000020091112
22222222220000780 000001013OLF-AA006500020091112
$
$ sort -k 1.2,1.10 -k 2.14,2.15 file1.dat
21111111110001343 000001004OLF-AA029100020091112
21111111110000060 000001004ODL-CH001000020091112
22222222220000780 000001013OLF-AA006500020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000060 000001039ODL-CH001000020091112
23333333330000111 000001039ODL-SP002000020091112
24444444440001416 000001045OLF-AA011800020091112
$
$

tyler_durden

Last edited by durden_tyler; 11-06-2009 at 11:41 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort date time in ascending order

Hi, i had a data block (coming from pipe from other codes) as: H YF_CO.dat 77164 11/17/2013 04:00:02 731374590.96 1 1 731374590.96 76586 77164 578 2988 Y H YF_CO.dat 77164 11/17/2013 04:00:07 731374590.96 1 4 731374590.96 76586 77164 578 2988 Y H YF_CO.dat 77178 ... (5 Replies)
Discussion started by: pr5439
5 Replies

2. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

3. UNIX for Dummies Questions & Answers

How to sort a column based on numerical ascending order if it includes e-10?

I have a column of numbers in the following format: 1.722e-05 2.018e-05 2.548e-05 2.747e-05 7.897e-05 4.016e-05 4.613e-05 4.613e-05 5.151e-05 5.151e-05 5.151e-05 6.1e-05 6.254e-05 7.04e-05 7.12e-05 7.12e-05 (6 Replies)
Discussion started by: evelibertine
6 Replies

4. UNIX for Dummies Questions & Answers

sort file returned by FIND command in ascending

Hi there I have to enhance my current file looping to ensure the oldest file being processed first. current command: for FILENAME in `find $MY_DIRECTORY -follow -type f` I manage to get command for order by date modified descending, just can't get the ascending order. Please help for... (3 Replies)
Discussion started by: elsie512
3 Replies

5. Shell Programming and Scripting

ascending and descending sort

Hi I have a problem with sort command : sort -nk 1.28,1.34 file | sort -nrk 1.27 file | sort -nk 1.22,1.25 file |sort -nk 1.13,1.21 file | sort -nk 1.9,1.12 file | sort -nk 1.1,1.8 file This is the input file 0000000100010000000200004090317003 0000000100010000000230001020592002... (3 Replies)
Discussion started by: Fafa
3 Replies

6. Programming

Sort ascending n strings in C

Hy guys. My English is not so good, sorry for any mistakes. I'm a bigginer in C, and I have a problem. I want to sort ascending n strings, but I can't read the strings. Here is what I've done so far: //sort ascending n strings #include <stdio.h> int main() { int n,i,j; char a; ... (8 Replies)
Discussion started by: 1/0
8 Replies

7. Linux

Using sort command to get numeric ascending order

HI everyone, I am trying to use the unix sort command to get a list of numbers sorted in ascending order but having trouble in getting it to work. An example of this issue would be when i am trying to sort the following three number each on a different line "1" , "2" and "116" the sort command... (3 Replies)
Discussion started by: wali4813
3 Replies

8. UNIX for Dummies Questions & Answers

Sort ascending and descending

How can I sort a file as follows ? cols 1 - 10 ascending cols 11 - 18 descending cols 19 - 20 ascending Thanks (1 Reply)
Discussion started by: don_0110
1 Replies

9. Shell Programming and Scripting

Ascending & Descending order numbers

Dear All, I have below attached file in which i have many nos, i want the last ascending order nos. The brief description is given below. File 315 381 432 315 381 432 315 381 432 315 381 432 315 381 432 (6 Replies)
Discussion started by: pravani1
6 Replies

10. UNIX for Dummies Questions & Answers

Sort / ascending order

What's the command to sort a file in ascending order and redirect the output to another file? Thanks!!!!!! (1 Reply)
Discussion started by: gyik
1 Replies
Login or Register to Ask a Question