Sponsored Content
Top Forums Shell Programming and Scripting Sort numerically a non numerical Post 302416492 by drewk on Monday 26th of April 2010 03:53:48 PM
Old 04-26-2010
Perl will do that. There is a '06' vs '0' and '6' in your data. The code below sorts the '06' with the '0' and not the '6' but this is easily changed.

Code:
#!/usr/bin/perl

while(<DATA>) {
   chomp;
   push @a, [split];
}

for $ref ( sort { ord($a->[1]) <=> ord($b->[1]) } @a) {
	print "@$ref\n";
}

__DATA__
01 * * * *
01 * * * *
01 * * * *
01 * * * *
01 0 * * *
01 0 * * *
01 0 * * *
01 0 * * *
02 * * * 0
02 * * * 0
02 * * * 6
02 * * * 6
02 0 * * 1
02 0 * * 1
02 0 * * 2
02 0 * * 2
02 0 * * 3
02 0 * * 3
02 0 * * 4
02 0 * * 4
02 0 * * 5
06 0 * * *
06 0 * * *
11 * * * *
11 * * * *
11 0 * * *
11 0 * * *
12 0 * * 0
12 0 * * 0
12 0 * * 1
12 0 * * 1
12 0 * * 2
12 0 * * 2
12 0 * * 3
12 0 * * 3
12 0 * * 4
12 0 * * 4
12 0 * * 5
12 0 * * 5
12 0 * * 6
12 0 * * 6
15 0 * * 1
15 0 * * 1
15 0 * * 2
15 0 * * 2
15 0 * * 3
15 0 * * 3
15 0 * * 4
15 0 * * 4
15 0 * * 5
15 0 * * 5
16 0 * * *
16 0 * * *
21 * * * *
21 0 * * *
31 * * * *
41 * * * *
51 * * * *
52 * * * *
55 * * * *
58 * * * *
02 1 * * 1
02 1 * * 2
02 1 * * 3
02 1 * * 5
04 1 * * *
12 1 * * 0
12 1 * * 1
02 06 * * 5
02 6 * * 4

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sort file alphabetically AND numerically

Hi all. I have 2 files like this: f1 A 10 B 80 C 9 f2 A 11 B 700 C 10 What I want is the concatenation of the two files sorted by name (alphabetically) and size (numerically), so the result should be like this: F3 (cat f1 f2 sorted) A 10 A 11 B 80 B 700 (2 Replies)
Discussion started by: mrodrig
2 Replies

2. Shell Programming and Scripting

Numerically sort problem for a long list of file name

I got a long list of file name. My input: data_1.txt data_2.txt data_3.txt data_10.txt data_21.txt data_12.txt data_4.txt My desired output: data_1.txt data_2.txt data_3.txt data_4.txt data_10.txt data_12.txt data_21.txt Does anybody got idea how to archive it? (11 Replies)
Discussion started by: patrick87
11 Replies

3. Shell Programming and Scripting

script to sort a string of numerical data in set fields

So, I will be working with someone and basically we are trying to build a form that is submitted most likely via the web and the data is just a string of numbers. like: 19383882872201110929282821818182827349190102837364718191001932873711 Now, each number is part of a numerical value of... (4 Replies)
Discussion started by: tlarkin
4 Replies

4. UNIX for Dummies Questions & Answers

Sort 2 columns numerically

Hi, A basic query. In the example file below, I want to sort by column 1 and then by column 2 numerically. I have tried sort -k2n,1 file1 but while this sorts the columns in the correct order, it does not sort column 2 numerically. Any help would be much appreciated. Also, if you have time to... (3 Replies)
Discussion started by: auburn
3 Replies

5. Shell Programming and Scripting

Sort alphabetically, then numerically

Greetings - I'm not necessarily new to bash scripting - I'm probably between beginner and intermediate, but I have something that I just cannot figure out after many attempts to find it. I have a file that is merely a list of many files, with their respective paths, and a branch path (ClearCase)... (5 Replies)
Discussion started by: 1cor29
5 Replies

6. 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

7. UNIX for Dummies Questions & Answers

[Solved] Reverse the order of a list of file names (but not sort them alphabetically or numerically)

Hello all, I have a list of file names in a text document where each file name consists of 4 letters and 3 numbers (for example MACR119). There are 48 file names in the document (they are not in alphabetical or numerical order). I would like to reorder the list of names so that the 48th name is... (3 Replies)
Discussion started by: MDeBiasse
3 Replies

8. Shell Programming and Scripting

Use sort to sort numerical column

How to sort the following output based on lowest to highest BE? The following sort does not work. $ sort -t. -k1,1n -k2,2n bfd.txt BE31.116 0s 0s DOWN DAMP BE31.116 0s 0s DOWN DAMP BE31.117 0s 0s ... (7 Replies)
Discussion started by: sand1234
7 Replies

9. UNIX for Beginners Questions & Answers

How to sort files in directory numerically?

Trying to sort a bunch of files numerically but can't seem to get the command just right. This is in a IBM AIX machine. I have a directory that has... backup.bk1 backup.bk100 backup.bk2 backup.bk200 backup.bk3 backup.bk300 There are a lot more files but this is shortened for the... (5 Replies)
Discussion started by: c3rb3rus
5 Replies
Prima::KeySelector(3)					User Contributed Perl Documentation				     Prima::KeySelector(3)

NAME
Prima::KeySelector - key combination widget and routines DESCRIPTION
The module provides a standard widget for selecting a user-defined key combination. The widget class allows import, export, and modification of key combinations. The module provides a set of routines, useful for conversion of a key combination between representations. SYNOPSIS
my $ks = Prima::KeySelector-> create( ); $ks-> key( km::Alt | ord('X')); print Prima::KeySelector::describe( $ks-> key ); API
Properties key INTEGER Selects a key combination in integer format. The format is described in "Hot key" in Prima::Menu, and is a combination of "km::XXX" key modifiers and either a "kb::XXX" virtual key, or a character code value. The property allows almost, but not all possible combinations of key constants. Only "km::Ctrl", "km::Alt", and "km::Shift" modifiers are allowed. Methods All methods here can ( and must ) be called without the object syntax; - the first parameter must not be neither package nor widget. describe KEY Accepts KEY in integer format, and returns string description of the key combination in human readable format. Useful for supplying an accelerator text to a menu. print describe( km::Shift|km::Ctrl|km::F10); Ctrl+Shift+F10 export KEY Accepts KEY in integer format, and returns string with a perl-evaluable expression, which after evaluation resolves to the original KEY value. Useful for storing a key into text config files, where value must be both human readable and easily passed to a program. print export( km::Shift|km::Ctrl|km::F10); km::Shift|km::Ctrl|km::F10 shortcut KEY Converts KEY from integer format to a string, acceptable by "Prima::AbstractMenu" input methods. print shortcut( km::Ctrl|ord('X')); ^X translate_codes KEY, [ USE_CTRL = 0 ] Converts KEY in integer format to three integers in the format accepted by "KeyDown" in Prima::Widget event: code, key, and modifier. USE_CTRL is only relevant when KEY first byte ( "KEY & 0xFF" ) is between 1 and 26, what means that the key is a combination of an alpha key with the control key. If USE_CTRL is 1, code result is unaltered, and is in range 1 - 26. Otherwise, code result is converted to the character code ( 1 to ord('A'), 2 to ord('B') etc ). AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>. SEE ALSO
Prima, Prima::Widget, Prima::Menu. perl v5.14.2 2009-02-24 Prima::KeySelector(3)
All times are GMT -4. The time now is 09:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy