How to sort a column of a file without sorting the rows?

2

I have a file that has three columns, and several rows. The second column is made up of numeric values, and I want to rearrange it, in ascending order, but without affecting the previous and subsequent column.

exemplo do arquivo:

7.31937  736    /tmp/ref13
7.3223   5373   /tmp/ref13
7.32816  768    /tmp/ref13
7.32955  5370   /tmp/ref10

o que eu quero:


7.31937  736    /tmp/ref13
7.3223   768    /tmp/ref13
7.32816  5370   /tmp/ref13
7.32955  5373   /tmp/ref10

I have tried sort -k2 -n , but this command is moving the other columns = (

Does anyone help me? Thanks!

Edit:

[Resolvido]Comando utilizado:

'paste -d' '  <(awk '{print $1}' nome_arquivo) <(awk '{print $2}' nome_arquivo | sort -n) <(awk '{print $3}' nome_arquivo)'
    
asked by anonymous 11.10.2016 / 15:29

1 answer

4

Script:

#!/bin/bash

INPUT=$1
OUTPUT=$2

awk '{ print $1 }' $INPUT           > $$.1
awk '{ print $2 }' $INPUT | sort -n > $$.2
awk '{ print $2 }' $INPUT           > $$.3

paste $$.1 $$.2 $$.3 > $OUTPUT
rm $$1 $$.2 $$.3
    
12.10.2016 / 06:58