据有点复杂条件下删除一些行 [英] Removing some lines according to a little complicated condition

查看:119
本文介绍了据有点复杂条件下删除一些行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文本文件的内容如下:

  600466一37.50 25.28
600466 b 31.13 18.22
600466Ç64.80 61.39
600467一38.79 30.00
600467 b 28.73 41.04
600467Ç58.32 61.39
600468一33.09 25.28
600468 b 35.57 42.69
600468Ç58.32 60.12
600469一36.89 29.80
600469 b 35.57 30.94
600469Ç64.80 62.49
600470 b 37.35 35.02 *
600470ç58.32 58.32 *
600471一29.22 25.47
600471 b 34.74 20.61
600471Ç64.80 62.81
600472 b 31.13 30.28 *
600472ç58.32 62.04 *

我查了一些线有星号。

您可以得到一个行的第一个字段中重复3次(所以会出现连续恰好3次),但有些线路都没有。我想删除该行与一些shell命令。

有没有人有一个奇特的想法?

(我的英语不好任何修正将受到欢迎。谢谢你提前)


解决方案

 切-d''-f1文件\\
| uniq的-c \\
|的grep -v'3'\\
|转速|切-d''-f1 |转\\
| grep的-vwFf-文件>产量

第一行输出的第一列。

第二行计算每个值多久是present。

第三条线不包括为present 3次的行。

第四行删除计数。

第五行从原始文件排除字符串。

Text file’s content is as follows.

600466 a 37.50 25.28
600466 b 31.13 18.22
600466 c 64.80 61.39
600467 a 38.79 30.00
600467 b 28.73 41.04
600467 c 58.32 61.39
600468 a 33.09 25.28
600468 b 35.57 42.69
600468 c 58.32 60.12
600469 a 36.89 29.80
600469 b 35.57 30.94
600469 c 64.80 62.49
600470 b 37.35 35.02 *
600470 c 58.32 58.32 *
600471 a 29.22 25.47
600471 b 34.74 20.61
600471 c 64.80 62.81
600472 b 31.13 30.28*
600472 c 58.32 62.04 *

I checked some lines with an asterisk.

You can get the first field of a line repeats 3 times(so it appears exactly 3 times consecutively), but some lines are not. I want remove that lines with a few shell commands.

Does anyone have a fancy idea?

(any correction of my poor English would be welcomed. Thank you for advance)

解决方案

cut -d' ' -f1 file \
| uniq -c \
| grep -v ' 3 ' \
| rev | cut -d' ' -f1 | rev \
| grep -vwFf- file > output

The first line outputs the first column.

The second line counts how often each value was present.

The third line excludes those lines that were present 3 times.

The fourth line removes the counts.

The fifth line excludes the strings from the original file.

这篇关于据有点复杂条件下删除一些行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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