The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-23-2005
bourne bourne is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 25
Question 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 ascending order... what can be done in unix to get the same order as in mainframes??
  #2 (permalink)  
Old 11-23-2005
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
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?
  #3 (permalink)  
Old 11-24-2005
bourne bourne is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 25
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??
  #4 (permalink)  
Old 11-24-2005
grasper grasper is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 45
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
  #5 (permalink)  
Old 11-24-2005
kefx kefx is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 4
An even simpler

$ sort -n inputfile

should take care of it.
  #6 (permalink)  
Old 11-25-2005
bourne bourne is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 25
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++;
}
}

Closed Thread

Bookmarks

Tags
perl, perl shift, shift, shift perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0