Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Inconsistent results using sort function Post 303027265 by aberg on Wednesday 12th of December 2018 04:17:55 PM
Old 12-12-2018
Inconsistent results using sort function

Could you please advise on the following: I have two space-delimited files with 9 and 10 columns, respectively, with exactly the same values in column 1. However, the order of column 1 differs between the two files, so I want to sort both files by column 1, so that I can align them and concatenate them into a 19 column file.


If I want to sort by column 1, I usually use "sort -k 1,1 -g". I have done this hundreds of times and I have never had a problem with it.
This is the first time ever that the sort function has given a different output for the two files, despite using identical commands:

Code:
sort -k 1,1 -g file1.txt | head

rs1000000 12 126890980 G A 0.772687 0.999152 -6.53289e-05 0.000341777  
rs10000003 4 57561647 A G 0.298872 0.997534 -0.000308206 0.000313536 
rs10000005 4 85161558 G A 0.468352 0.994261 0.000392384 0.000287513 
rs10000010 4 21618674 T C 0.517001 0.986406 -0.000387116 0.000288364  
rs10000011 4 138223055 C T 0.957162 0.987603 -0.000466108 0.000710431  
rs10000012 4 1357325 C G 0.85952 0.999131 -0.000544182 0.000412222  
rs10000017 4 84778125 C T 0.777348 0.989758 0.00024644 0.000345697  
rs10000018 4 100458448 A G 0.707724 0.999129 -5.96813e-05 0.000315027  
rs10000021 4 159441457 G T 0.185355 0.99682 0.000127756 0.000369005  
rs1000002 3 183635768 C T 0.513401 1 -0.000269255 0.000286993 3.5E-01

and

Code:
sort -k 1,1 -g file2.txt | head 

rs10000003 G A 0.707825 1.010846 0.015580 0.980310 1.042333 0.490663
rs10000005 A G 0.550104 0.988740 0.014283 0.960744 1.017551 0.439681
rs1000000 G A 0.780117 0.987172 0.017380 0.953108 1.022454 0.471168 
rs10000010 C T 0.503288 1.009101 0.014611 0.980464 1.038574 0.537391 
rs10000011 C T 0.950554 0.997444 0.026380 0.945740 1.051976 0.924913 
rs10000012 C G 0.866931 0.966905 0.021645 0.924482 1.011276 0.141498 
rs10000017 C T 0.791953 1.003966 0.019870 0.965021 1.044483 0.844517 
rs10000018 A G 0.699162 1.006137 0.014434 0.977846 1.035245 0.674194 
rs10000021 T G 0.827782 0.991092 0.021206 0.949529 1.034474 0.682292 
rs10000023 T G 0.579281 1.024738 0.014014 0.997270 1.052962 0.077937

Why is this happening despite identical commands? I'm especially puzzled because I have never encountered this before.

Thank you for any advice.

aberg
 

10 More Discussions You Might Find Interesting

1. Programming

sort function

do any one knows where i can find an implementation in c for the sort function (2 Replies)
Discussion started by: dbargo
2 Replies

2. UNIX for Dummies Questions & Answers

How to sort find results

Hi-- Ok. I have now found that: find -x -ls will do what I need as far as finding all files on a particular volume. Now I need to sort the results by the file's modification date/time. Is there a way to do that? Also, I notice that for many files, whereas the man for find says ls is... (8 Replies)
Discussion started by: groundlevel
8 Replies

3. Shell Programming and Scripting

sort function in perl

Hi, here is my perl script.This script creates an array and is sorting it using the in-built sort function in perl. #!/usr/local/bin/perl my number=6; my @num_arr=(1,2,3,4,5); my @array=(23,"$number","Hello",2.345,@num_arr); #printing the array print... (2 Replies)
Discussion started by: DILEEP410
2 Replies

4. Shell Programming and Scripting

HELP: I need to sort a text file in an uncommon manner, can't get desired results

Hi All I have a flat text file. Each line in it contains a "/full path/filename". The last three columns are predictable, but directory depth of each line varies. I want to sort on the last three columns, starting from the last, 2nd last and 3rd last. In that order. The last three columns... (6 Replies)
Discussion started by: JakeKatz
6 Replies

5. Shell Programming and Scripting

Not able to store the results of perl recursive function when applied under for loop

Hi Perl Gurus , need URGENT HELP PLEASE !!!!! I have one recursive Perl function which takes path of any directory as argument and returns array containing all the sub folders inside it recursively. Now the problem is that it works well if i use it with one time but the problem is that when... (0 Replies)
Discussion started by: anthriksh2000
0 Replies

6. Shell Programming and Scripting

Help with sort folder results

Here is the code, but the list is not sorted properly (alphabetically)? <?php function folderlist(){ $startdir = './'; $ignoredDirectory = '.'; $ignoredDirectory = '..'; if (is_dir($startdir)){ if ($dh = opendir($startdir)){ while (($folder = readdir($dh)) !== false){ if... (0 Replies)
Discussion started by: mrlayance
0 Replies

7. UNIX for Dummies Questions & Answers

sort find results

Hi, I have a problem with a shell script. The script should find all .cpp and .h files and list them. With: for file in `find $src -name '*.h' -o -name '*.cpp' it gives out this: H:\FileList\A\E\F\G\newCppFile.cpp H:\FileList\header01.h H:\FileList\B\nextCppFile.cpp ... (4 Replies)
Discussion started by: shellBeginner75
4 Replies

8. UNIX for Dummies Questions & Answers

LINUX SORT command chops results

I am trying to sort a file . The file looks like this: DDFF 2 /ztpfrepos/pgr/load DDFQ 2 /ztpfrepos/pgr/load DDFX 2 /ztpfrepos/pgr/load DDUA 2 /ztpfrepos/pgr/load My command: sort -k1 /home/c153507/Bin/OPL1.txt -o /home/c153507/Bin/OPL1.txt The results are OK except for one line where... (4 Replies)
Discussion started by: Yahalom
4 Replies

9. UNIX for Beginners Questions & Answers

Strange sort -r results

Hi Folks - I have this file that looks like this: outbox/logs/Client_1042.log outbox/logs/Client_941.log outbox/logs/Client_942.log outbox/logs/Client_943.log outbox/logs/Client_944.log And this is my code: #!/bin/bash _OUTBOX_BIN="outbox/logs/" _NAME="Client" _TEMP="temp.txt"... (9 Replies)
Discussion started by: SIMMS7400
9 Replies

10. UNIX for Beginners Questions & Answers

Strange results from 'strings | sort'

Using the 'strings' command and piping the result to 'sort' is producing strange results. I get block of lines that begin with asterisks, then a block that begins with some text, then more lines that begin with asterisks. The actual content is correct - lines beginning with asterisks is the... (5 Replies)
Discussion started by: edstevens
5 Replies
DCSORT(1)					      DICOM PS3 - Make sorted list of images						 DCSORT(1)

NAME
dcsort - ACR/NEMA DICOM PS3 ... DICOM PS3 - Make sorted list of images SYNOPSIS
dcsort " inputfile1 [ inputfile2 ... ]" [ -v|verbose ] [ -vv|veryverbose ] [ -vvv|veryveryverbose ] [ -index ] [ -show ] [ -interval ] [ -tolerance mm ] [ -check ] [ -checkFoR ] [ -descending ] [ -sortby|k attributename ] DESCRIPTION
dcsort reads the named dicom input files and sorts them by the specified sort key. The sort key should be a single valued numeric attribute, with the exception of ImageOrientationPatient and ImagePositionPatient which are handled as special cases. There is no output by default unless the index or verbose options are specified. OPTIONS
The output and errors go to standard error. The basic input switches are described in dcintro(1). Options specific to this program are: -index Creates a first column of output that is the index in the sort order, starting from 0, and a second column that is the filename. -show Show the value of the sort key after the file name with the -index option -interval Show the interval between values of the sort key, or an error if not equal -tolerance mm The tolerance value in mm to use when comparing intervals between slices; defaults to +/- 0.01 mm if unspecified -check Check that all the images are from the same series. -checkFoR Check that all the images have the same Frame of Reference (UID). -descending Sort in descending, rather than the default ascending, order. -sortby|k attributename Specify attributename as the sort key. ENVIRONMENT
EXAMPLES
% dcsort -index -sortby SliceLocation ./1/[0-9]* 0 ./1/1 1 ./1/2 FILES
SEE ALSO
dcintro(1) AUTHOR
Copyright (C) 1993-2010. David A. Clunie DBA PixelMed Publishing. All rights reserved. BUGS
DICOM PS3 22 December 2006 DCSORT(1)
All times are GMT -4. The time now is 05:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy