AWK - 如何做选择多列排序? [英] AWK -- How to do selective multiple column sorting?

查看:500
本文介绍了AWK - 如何做选择多列排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在awk中,我怎么可以这样做:

In awk, how can I do this:

输入:

1  a  f  1  12  v  
2  b  g  2  10  w  
3  c  h  3  19  x  
4  d  i  4  15  y  
5  e  j  5  11  z  

所需的输出,通过在 $ 5 排序数值:

1  a  f  2  10  w  
2  b  g  5  11  z  
3  c  h  1  12  v  
4  d  i  4  15  y  
5  e  j  3  19  x  

注意的排序应影响 $ 4'/ code>, $ 5 $ 6个(基于价值 $ 5 ),其中表的previous部分保持不变。

Note that the sorting should only affecting $4, $5, and $6 (based on value of $5), in which the previous part of table remains intact.

推荐答案

这可以在多个步骤完成与<一个帮助href=\"https://www.gnu.org/software/coreutils/manual/html_node/paste-invocation.html\"><$c$c>paste:

This could be done in multiple steps with the help of paste:

$ gawk '{print $1, $2, $3}' in.txt > a.txt
$ gawk '{print $4, $5, $6}' in.txt | sort -k 2 -n b.txt > b.txt
$ paste -d' ' a.txt b.txt
1 a f 2 10 w
2 b g 5 11 z
3 c h 1 12 v
4 d i 4 15 y
5 e j 3 19 x

这篇关于AWK - 如何做选择多列排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆