2016-10-11 6 views
-2

誰かが私にこのことをどうやって説明することができますか? 私は3つの列とたくさんの行を持つファイルを持っています。そして、2番目の列を昇順で並べ替える(数字のみを含む)ようにします。行を整列せずに列を整列するにはどうすればよいですか?

sample file; 

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

私はしたいです;

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

ありがとう!!

+1

あなたがこれまでに試してみましたか?より多くの助けを得るようにこの努力を示すことは良いことです。 http://stackoverflow.com/help/how-to-ask – micstr

答えて

0

これを試すことができます。

paste -d' ' <(awk '{print $1}' yourFile) <(awk '{print $2}' yourFile | sort -n) <(awk '{print $3}' yourFile) 

または

awk '{print $2}' yourFile | sort -n | paste yourFile - | awk '{print $1"\t"$4"\t"$3}' 

例:

[email protected]:/tmp$ cat t1 
7.31937 736 /tmp/ref13 
7.3223 5373 /tmp/ref13 
7.32816 768 /tmp/ref13 
7.32955 5370 /tmp/ref10 

[email protected]:/tmp$ paste -d' ' <(awk '{print $1}' t1) <(awk '{print $2}' t1 | sort -n) <(awk '{print $3}' t1) | column -t 
7.31937 736 /tmp/ref13 
7.3223 768 /tmp/ref13 
7.32816 5370 /tmp/ref13 
7.32955 5373 /tmp/ref10 
+0

おかげで多くのことを参照してくださいが、それは仕事のD doesntの:あなたは更新でき 7.31937 \tを/ tmp/ref13 – miloski

+0

:行はこのようなものです をサンプルファイルの質問は "7.31937/tmp/ref13" –

+0

私は質問を変更しました! あなたのコードは最初の列を移動しています=( – miloski

関連する問題