![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sort a file in reverse order | frustrated1 | Shell Programming and Scripting | 11 | 09-21-2005 04:41 PM |
| replacing characters in order to sort | gammaman | UNIX for Dummies Questions & Answers | 5 | 08-02-2005 10:56 AM |
| Sort - original order .... Help | olga | UNIX for Dummies Questions & Answers | 2 | 06-01-2005 09:26 AM |
| Echo display alignment/sort order | shackman66 | Shell Programming and Scripting | 1 | 05-10-2004 06:12 AM |
| Sort / ascending order | gyik | UNIX for Dummies Questions & Answers | 1 | 03-05-2001 10:08 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 ascending order... what can be done in unix to get the same order as in mainframes??
![]() |
|
||||
|
But this wont work if my input data can be like this...
A1234a c2345a B1234a a1235a c1235c b1235b i have got a code in perl... but cud not make out wat the hash sort means.. can any1 help? #!/bin/perl my @order=("a", "b", "c", "1", "2", "3", "A", "B", "C","z"); # Order Characters; Entire EBCDIC character set needs to be defined here my %sorthash; # For quicker sorting the sub initiliaze() puts the list @order into a hash. my @strings=("ABC123", "123ABC", "abcABC", "ABCabc", "abc123", "123abc","zzz123"); # Sort List initialize(); # Puts the ordering into a hash of the format ("a" => 1, "A" => 2, "\342" => 3, "\302" => 4, ...) my $string; foreach $string (sort @strings) { # Normal way of sorting in perl, but sort now calls "mysort" for getting the right ordering print $string."\n"; } sub mysort { # Compares two elements x and y my $word1=$a; my $word2=$b; return 0 if ($word1 eq $word2); my @word1=split("", $word1); my @word2=split("", $word2); while ((@word1 > 0) and (@word2 > 0)) { my $char1=shift @word1; my $char2=shift @word2; my $compare=($sorthash{$char2}<=>$sorthash{$char1}); return $compare if ($compare != 0); } if (@word1) { return 1; } else { return -1; } } sub initialize { my $i=1; my $entry; foreach $entry (@order) { $sorthash{$entry}=$i; $i++; } } ![]() |
![]() |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|