Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Sort command in one column and not effect to another column Post 302784441 by radoulov on Friday 22nd of March 2013 07:51:48 AM
Old 03-22-2013
Code:
perl -F'\s*=\s*' -lane'
  push @f, $F[0];
  push @s, $F[1];
  END {
    @ss = sort { $a <=> $b } @s;
    for (sort { $a <=> $b } @f) {
      printf "%s = %s\n", $_, shift @ss 
      }    
    }' infile

Or (if your shell supports process substitution):

Code:
paste -d= <(cut -d= -f1 infile | sort -n) <(cut -d= -f2 infile | sort -n)


Last edited by radoulov; 03-22-2013 at 09:09 AM..
This User Gave Thanks to radoulov For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sort by the third column with +n command

my data.file: 1 2 3 3 2 1 3 5 8 4 9 11 3 3 30 I sort it by the 3rd column: sort -k3b,3 data.file I have : 3 2 1 4 9 11 1 2 3 3 3 30 3 5 8 How can I sort the 3rd column with the +n command? (2 Replies)
Discussion started by: bobo
2 Replies

2. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

3. Shell Programming and Scripting

Question about sort specific column and print other column at the same time !

Hi, This is my input file: ali 5 usa abc abu 4 uk bca alan 6 brazil bac pinky 10 utah sdc My desired output: pinky 10 utah sdc alan 6 brazil bac ali 5 usa abc abu 4 uk bca Based on the column two, I want to do the descending order and print out other related column at the... (3 Replies)
Discussion started by: patrick87
3 Replies

4. Shell Programming and Scripting

sort on second column only based on first column

I have an input file like this... AAAlkalines Energizer AAAlkalines Energizer AAAlkalines Energizer AAAlkalines Sunlight AAAlkalines Sunlight AAAlkalines Sunlight AAAlkalines Energizer AAAlkalines Energizer AAAlkalines Energizer AAASalines ... (7 Replies)
Discussion started by: malcomex999
7 Replies

5. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

6. Shell Programming and Scripting

command for converting 4 column data to 1 column

dear friends I want to convert four column data to one column data. For example: from 1, 2, 3, 4 5, 6, 7, 8to 1 2 3 4 5 6 7 8what is the general command for that type of convertion. thanks (5 Replies)
Discussion started by: rpf
5 Replies

7. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

8. Shell Programming and Scripting

Difference of the same column when two other column matches and one column differs less than 1 hour

This is my input file : # cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9 This is the required output ... (1 Reply)
Discussion started by: Lakshmikumari
1 Replies

9. Shell Programming and Scripting

Help with sort First Column followed by Second Column

Input file: DN63688_c0_g1 DN63688_c0_g1_i1 DN71_c0_g1 DN71_c0_g1_i1 DN63688_c0_g1 DN63688_c0_g1_i2 DN63688_c0_g1 DN63688_c0_g1_i3 DN63688_c0_g1 DN63688_c0_g1_i7 DN134_c0_g1 DN134_c0_g1_i1 DN63688_c0_g1 DN63688_c0_g1_i8 DN63688_c0_g1 DN63688_c0_g1_i9 DN63688_c0_g1 ... (3 Replies)
Discussion started by: perl_beginner
3 Replies

10. 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
Data::Pager(3pm)					User Contributed Perl Documentation					  Data::Pager(3pm)

NAME
Data::Pager - flexible data pager SYNOPSIS
use Data::Pager; my $pager = Data::Pager->new({ current => 100, perpage => 10, offset => 5, limit => 2000, }); #~ accessors: $pager->current; # 100 $pager->next; # 101 $pager->prev; # 99 $pager->limit; # 2000 $pager->start; # 1 # not typical start of a programmer $pager->final; # # 400 (which denotes 2000 / 5 pager links) $pager->end; # / $pager->from; # 495 (may serve in SQL LIMIT clause) $pager->to; # 500 (may serve in SQL LIMIT clause) $pager->list; # 95 96 97 98 99 100 101 102 103 104 105 DESCRIPTION
This class implements the familiar pager where the current position is centered. CONSTRUCTOR
new my $pager = Data::Pager->new({ current => 1, # this is the current pager position perpage => 10, # the pager consists of this number of links (defaults to 10) offset => 5, # this is the number of results (fetched from the DB for example) per result limit => 100, # how far is the pager allowed }); # sample output from html table: id ... ..... ... 1. ... ..... ... 2. ... ..... ... 3. ... ..... ... 4. ... ..... ... 5. ... ..... ... 1 2 3 4 5 6 7 8 9 10 Returns object or undef if current position is beyond the limit. METHODS
current $pager->current(); Returns the current pager position. set_current($digit) $pager->set_current(850); $pager->set_current(850)->next(); Sets the current pager position. Returns the pager object on succes, undef on false. next Returns the next pager position or undef if this is the last one. prev Returns the previous pager position or undef if this is the first one. start Returns 1 - the start pager position. end Returns the end pager position. first Returns the first pager position for this result set. last Returns the last pager position for this result set. from '1' => { 'to' => 5, 'next' => 2, 'prev' => undef, 'from' => 0 }, '2' => { 'to' => 10, 'next' => 3, 'prev' => 1, 'from' => 5 }, ... Returns the start result this pager position refers to. to Returns the end result this pager position refers to. list @_ = $pager->list; $_ = $pager->list; Returns the pager links for this result set. In list context returns the resulting list. In scalar context returns reference to the resulting list. # note the alignment $pager->set_current(10); print $pager->list; # 6 7 8 9 [10] 11 12 13 14 15 $pager->set_current(33); print $pager->list; # 28 29 30 31 32 [33] 34 35 36 37 38 SEE ALSO
Data::Page BUGS
What BUGS? AUTHOR
Vidul Nikolaev Petrov, vidul@cpan.org COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.10.0 2006-04-04 Data::Pager(3pm)
All times are GMT -4. The time now is 05:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy