Sponsored Content
Top Forums Shell Programming and Scripting Use sort to sort numerical column Post 303035328 by sand1234 on Tuesday 21st of May 2019 08:38:43 AM
Old 05-21-2019
reviewing solutions

reviewing solutions

--- Post updated at 12:38 PM ---

Hi,

1st solution works:

Code:
$ sed 's/^ *//' bfd.txt | sort -bV

BE31.116              0s               0s               DOWN DAMP
BE31.116               0s               0s               DOWN DAMP
BE31.117              0s               0s               DOWN DAMP
BE31.702                 0s               0s               DOWN DAMP
BE31.961              0s               0s               DOWN DAMP
BE31.3918           0s               0s               DOWN DAMP
BE62.2040               0s               0s               DOWN DAMP

2nd solution fails:

Code:
$ sed 's/^ *//' bfd.txt | sort -k1.3,1n

BE31.116              0s               0s               DOWN DAMP
BE31.116              0s               0s               DOWN DAMP
BE31.117               0s               0s               DOWN DAMP
BE31.3918             0s               0s               DOWN DAMP  <----- incorrect
BE31.702                 0s               0s               DOWN DAMP
BE31.961            0s               0s               DOWN DAMP
BE62.2040               0s               0s               DOWN DAMP

Can you please shed some light on why the 2nd solution does not work?
Also, why do we need 1n after -k1,3? I get the same result with and without this switch.

Thanks,

Last edited by Scrutinizer; 05-21-2019 at 11:52 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

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

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. Shell Programming and Scripting

Sort numerically a non numerical

Hello, I have this sample 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 (3 Replies)
Discussion started by: gio001
3 Replies

5. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 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. Shell Programming and Scripting

Help with sort word and general numeric sort at the same time

Input file: 100%ABC2 3.44E-12 USA A2M%H02579 0E0 UK 100%ABC2 5.34E-8 UK 100%ABC2 3.25E-12 USA A2M%H02579 5E-45 UK Output file: 100%ABC2 3.44E-12 USA 100%ABC2 3.25E-12 USA 100%ABC2 5.34E-8 UK A2M%H02579 0E0 UK A2M%H02579 5E-45 UK Code try: sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies

8. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

9. UNIX for Beginners Questions & Answers

Gawk: PROCINFO["sorted_in"] does not sort my numerical array values

Hi, PROCINFO seems to be a great function but I don't manage to make it works. input: B,A,C B B,B As an example, just want to count the occurence of each letter across the input and sort them by decreased order. Wanted output: B 4 A 1 C 1 When I use this command, the PROCINFO... (4 Replies)
Discussion started by: beca123456
4 Replies
GL-117(6)							  gl-117 overview							 GL-117(6)

NAME
gl-117 - an OpenGL action flight simulator SYNOPSIS
gl-117 [-dlevel -h -v] DESCRIPTION
gl-117 is an OpenGL and SDL based action flight simulator written in ISO C++. Enter the Eagle Squadron and succeed in several challanging missions leading though different landscapes. Five predefined levels of video quality and an amount of viewing ranges let you perfectly adjust the game to the performance of your system. The game provides joystick and mouse support, sound effects, and music. OPTIONS
-dlevel Set the debug level to level in [0..5]. '0' means quiet and will avoid any output, '1' will log fatal errors causing the program to crash on stderr, '2' will also print exceptions on stderr, '3' will add warnings on stdout, '4' prints additional information (pre- defined) on stdout, and '5' gives developer specific messages on stdout. -h Print a short summary on stdout and then quit immediately. -v Display the version number of gl-117 and then quit immediately. CONFIGURATION
gl-117 uses a predefined working directory ".gl-117" in the user's home directory to load and store all savegame files and read the plain text configuration files "conf" and "conf.interface". If there are no config files available, gl-117 will create them using standard set- tings. The contents of the files are quite self-explanatory. DOCUMENTATION
Please look at the gl-117 user manual (gl-117.pdf) for installation instructions and further gameplay related descriptions. COPYRIGHT
gl-117 is distributed under the terms of the GPL. AUTHORS
Thomas A. Drexl (tom.drexl@gmx.de) 27 February 2003 GL-117(6)
All times are GMT -4. The time now is 05:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy