如何对包含某个单词的行的列进行排序 [英] How to sort on column for rows containing a certain word

查看:17
本文介绍了如何对包含某个单词的行的列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想对包含某个单词的行对某个列进行排序.我不想看到不包含该词的行.例如我有这个文本文件:

I want to sort on a certain column only for rows containing a certain word. I don't want to see rows not containing that word. For example I have this text file:

 sdf ggfds   7
 sdf sgs     5
 sdf dfgs    3
 foo dffg    2
 bar dffg    2
 sdf sddfg   4

我想对仅包含sdf"单词的行进行第三列排序(不必在第一列中)

I want to sort 3rd column for rows containing only "sdf" word (doesnt have to be in a first column)

我想看到这个输出:

 sdf dfgs    3
 sdf sddfg   4
 sdf sgs     5
 sdf ggfds   7

推荐答案

将您的输入传送到外部命令:

Pipe your input to an external command:

:%!grep sdf | sort -n -k3

详情:

  1. 使用%"选择整个内容
  2. 使用!"将其通过管道传输到外部命令
  3. grep onyl 包含 'sdf' 的行
  4. 在第三个字段 (-k3) 上按数字 (-n) 对这些行进行排序

这篇关于如何对包含某个单词的行的列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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