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??
You can look at the -n and -r options but since I don't have a mainframe to test on, I don't know what you are truely looking for. Can you post a sample of input and output expected?
here is the sample :
123456
ABCDEF
245678
abcdef
the unix output:
123456
245678
ABCDEF
abcdef
the expected output:
ABCDEF
abcdef
123456
245678
can u get a code snippet for this??
Well, it may seem a bit lame, but if it's only alphanumeric data a small script would accomplish this, along the lines of:-
#!/bin/ksh
grep '[A-Z]' $1 |sort
grep '[a-z]' $1 |sort
grep '[0-9]' $1 sort
An even simpler
$ sort -n inputfile
should take care of it.
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++;
}
}