Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Sort array elements from same field Post 302819015 by MadeInGermany on Monday 10th of June 2013 05:25:20 AM
Old 06-10-2013
Good idea! But order should be
Code:
sort -t'@' -k1.1,1.5 -k2,2n inputfile

Sort on the first key field until the '|' separator, and secondary numerical sort on the 2nd key field.
This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Deleting Array Elements

Hi, I am writing a BASH shell script. I have an array that will contain IN ANY ORDER the following elements: DAY 8D MO NS. I would like to erase the element DAY, but since the order of the elements in the array are random, I will not know which element # DAY is (ie it's not as simple as... (3 Replies)
Discussion started by: msb65
3 Replies

2. Shell Programming and Scripting

Accessing array elements

Hi, My doubt is how to access array elements.. Situation is as below: #!/bin/ksh set -x typeset -i x=0 typeset -i y=0 typeset -i BID=0 typeset -i count=0 while ] ; do x=`expr $x + 1`; hwmgr show scsi > scsi.tmp while read line; do set... (1 Reply)
Discussion started by: mansa
1 Replies

3. Shell Programming and Scripting

Array with String Elements

How can I get my array to understand the double-quotes I'm passing into it are to separate text strings and not part of an element? here's what I'm working with... db2 -v connect to foo db2 -x "select '\"' || stats_command || '\",' from db2law1.parallel_runstats where tabname = 'BAZ'" set... (4 Replies)
Discussion started by: djschmitt
4 Replies

4. Shell Programming and Scripting

perl sort array by field

Hi Everyone, Any simple code can simplify the code below, please advice. Thanks # cat 2.pl #!/usr/bin/perl use warnings; use strict; my @aaaaa = <DATA>; my @uids; foreach (@aaaaa) { my @ccccc = split (",", $_); push @uids, $ccccc;... (3 Replies)
Discussion started by: jimmy_y
3 Replies

5. UNIX for Dummies Questions & Answers

Help with replacing Array elements

Hi, I have an array containing following sample information @array = qw (chr02 chr02 chr02 chr02 chr02 chr03 chr03 chr04 chr04 chr05 chr05 chr05 chr07 chr07) I need to replace all duplicate entries by an underscore to get the following output@array = qw (chr02 _ _ _ _ chr03 _ chr04 _ chr05 _ _... (4 Replies)
Discussion started by: pawannoel
4 Replies

6. UNIX for Dummies Questions & Answers

printing array elements

Is there a way to print multiple array elements without iterating through the array using bash? Can you do something like... echo ${array}and get all those separate elements from the array? (2 Replies)
Discussion started by: jrymer
2 Replies

7. Shell Programming and Scripting

Removing elements from an array

Hi I have two arrays : @arcb= (450,625,720,645); @arca=(625,645); I need to remove the elements of @arca from elements of @arcb so that the content of @arcb will be (450,720). Can anyone sugget me how to perform this operation? The code I have used is this : my @arcb=... (3 Replies)
Discussion started by: rkrish
3 Replies

8. Shell Programming and Scripting

Grouping array elements - possible?

I have a script which takes backup of some configuration files on my server. It does that by using an array which contains the complete path to the files to backup. It copys the files to a pre defined dir. Each "program" has it's own folder, ex. apache.conf is being copied to /predefined... (7 Replies)
Discussion started by: dnn
7 Replies

9. Shell Programming and Scripting

Random elements from array

Hi I wanted to print random elements from an array at bash shell I use the following code, but I always see first element getting printed #!/bin/bash c=1 expressions=(pink red white yellow purple) while ]; do echo "The value of RANDOM is $RANDOM" selectedexpression=${expressions}]};... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

10. Shell Programming and Scripting

Help reading the array and sum of the array elements

Hi All, need help with reading the array and sum of the array elements. given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large. Input Format The first line of the input consists of an... (1 Reply)
Discussion started by: nishantrefound
1 Replies
sort5(1)						      General Commands Manual							  sort5(1)

Name
       sort5 - internationalized System 5 sort and/or merge files

Syntax
       sort5 [-cmu] [-ooutput] [-ykmem] [-zrecsz] [-X] [-dfiMnr] [-btx] [+pos1 [-pos2]] [files]

Description
       The  command  sorts lines of the named files together and writes the result on the standard output.  The standard input is read if a hyphen
       (-) is used as a file name or if no input files are named.

       Comparisons are based on one or more sort keys extracted from each line of input.  By default, there is one  sort  key,	the  entire  input
       line,  and  ordering is determined by the collating sequence specified by the LC_COLLATE locale. The LC_COLLATE locale is controlled by the
       settings of either the LANG or LC_COLLATE environment variables. See for more information.

Options
       The following options alter the default behavior:

       -c   Checks that the input file is sorted according to the ordering rules; gives no output unless the file is out of order.

       -m   Merges only; the input files are already sorted.

       -u   Suppresses all but one in each set of lines having equal keys.

       -ooutput
	    Specifies the name of an output file to use instead of the standard output.  The file may be the same as one of  the  inputs.   Blanks
	    between -o and output are optional.

       -ykmem
	    Specifies  the  number  of	kilobytes  of  memory  to use when sorting a file.  If this option is omitted, sort5 begins using a system
	    default memory size, and continues to use more space as needed.  If kmem is specified, sort5 starts using that number of kilobytes	of
	    memory.   If  the administrative minimum or maximum is violated, the value of the corresponding minimum or maximum is used.  Thus, -y0
	    is guaranteed to start with minimum memory.  By convention, -y (with no argument) starts with maximum memory.

       -zrecsz
	    Records the size of the longest line read in the sort phase so buffers can be allocated during the merge phase.  If the sort phase	is
	    omitted using either the -c or -m options, a system default size is used.  Lines longer than the buffer size cause to terminate abnor-
	    mally.  Supplying the actual number of bytes (or some larger value) in the longest line to be merged prevents abnormal termination.

       -X   Sorts using tags. Upon input each key is converted to a tag value which is sorted efficiently. This option makes international sorting
	    faster but it consumes more memory since both key and tag must be stored.

       The following options override the default ordering rules:

       -d   Specifies Dictionary order.  Only letters, digits and blanks (spaces and tabs) are significant in comparisons.

       -f   Folds lower case letters into upper case.

       -i   Ignores characters outside the ASCII range 040-0176 in non-numeric comparisons.

       -n   Sorts  an  initial	numeric  string, consisting of optional blanks, optional minus sign, and zero or more digits with optional decimal
	    point, by arithmetic value.  The -n option implies the -b option, which tells the command to ignore leading  blanks  when  determining
	    the starting and ending positions of a restricted sort key.

       -r   Reverses the sense of comparisons.

       When ordering options appear before restricted sort key specifications, the requested ordering rules are applied globally to all sort keys.
       When attached to a specific sort key (described below), the specified ordering options override all global ordering options for that key.

       The notation +pos1 -pos2 restricts a sort key to one beginning at pos1 and ending at pos2.  The characters at positions pos1 and  pos2  are
       included in the sort key (provided that pos2 does not precede pos1).  A missing -pos2 means the end of the line.

       Specifying  pos1  and pos2 involves the notion of a field, that is a minimal sequence of characters followed by a field separator or a new-
       line.  By default, the first blank of a sequence of blanks acts as the field separator.	The blank can be either a space  or  a	tab.   All
       blanks  in a sequence of blanks are interpreted as a part of the next field; for example, all blanks at the beginning of a line are consid-
       ered to be part of the first field.  The treatment of field separators is altered using the following options:

       -tx  Uses x as the field separator character.  Although it may be included in a sort key, x is not considered part of a field.  Each occur-
	    rence of x is significant (for example, xx delimits an empty field).

       -b   Ignores  leading  blanks  when  determining the starting and ending positions of a restricted sort key.  If the -b option is specified
	    before the first +pos1 argument, it is applied to all +pos1 arguments.  Otherwise, the b flag may be attached  independently  to  each
	    +pos1 or -pos2 argument.

       Pos1  and  pos2	each  have  the form m.n optionally followed by one or more of the flags bdfinr.  A starting position specified by +m.n is
       interpreted to mean the n+1st character in the m+1st field.  A missing .n means .0, indicating the first character of the m+1st field.	If
       the  b  flag  is  in  effect n is counted from the first non-blank in the m+1st field; +m.0b refers to the first non-blank character in the
       m+1st field.

       A last position specified by -m.n is interpreted to mean the nth character (including separators) after the last  character  of	the  m	th
       field.  A missing .n means .0, indicating the last character of the mth field.  If the b flag is in effect n is counted from the last lead-
       ing blank in the m+1st field; -m.1b refers to the first non-blank in the m+1st field.

       When there are multiple sort keys, later keys are compared only after all earlier keys are found to be equal.  Lines that otherwise compare
       equal are ordered with all bytes significant.

Examples
       Sort the contents of infile with the second field as the sort key:

	      sort5 +1 -2 infile

       Sort,  in  reverse  order,  the	contents of infile1 and infile2, placing the output in outfile and using the first character of the second
       field as the sort key:

	      sort5 -r -o outfile +1.0 -1.2 infile1 infile2

       Sort, in reverse order, the contents of infile1 and infile2 using the first non-blank character of the second field as the sort key:

	      sort5 -r +1.0b -1.1b infile1 infile2

       Print the password file sorted by the numeric user ID (the third colon-separated field):

	      sort5 -t: +2n -3 /etc/passwd

       Print the lines of the already sorted file infile, suppressing all but the first occurrence of lines  having  the  same	third  field  (the
       options -um with just one input file make the choice of a unique representative from a set of equal lines predictable):

	      sort5 -um +2 -3 infile

Diagnostics
       Comments  and exits with non-zero status for various trouble conditions (for example, when input lines are too long), and for disorder dis-
       covered under the -c option.

       When the last line of an input file is missing a new-line character, sort5 appends one, prints a warning message, and continues.

Files
       /usr/tmp/stm???

See Also
       comm(1), join(1), uniq(1), setlocale(3int), strcoll(3int)

																	  sort5(1)
All times are GMT -4. The time now is 06:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy