按匹配字符串对列进行排序列

按匹配字符串对列进行排序列

我有制表符分隔的文件,我只想对 red_ball 进行排序,如下所示

输入.txt

id      tagid    name
HH556   EN76     red_ball
JH678   EN45     green_ball
MH678   CV67     red_ball
TY896   RT56     red_ball

输出.txt

Red_ball

id  tagid
HH556   EN76
MH678   CV67
TY896   RT56

答案1

{
  printf 'Red_ball\nid\ttagid\n\n'
  awk -F'\t'  'NR>1 && $3 == "red_ball" {print $1 "\t" $2}' < input.txt |
    sort
} > output.txt

相关内容