如何删除BASH中仅包含数字的行? [英] How to delete lines containing only numbers in BASH?

查看:96
本文介绍了如何删除BASH中仅包含数字的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TXT文件.如何删除仅包含数字的行.例如:

I have a TXT file. How can I delete only those lines which only contain numbers. For e.g.:

This has some text.
1300
This has some more text.
1210
This has a text and some numbers. 12

在上面的示例中,只有第2行和第4行会被删除,因为它们是除数字之外没有其他符号的行.

In the sample above, only lines 2 and 4 would be deleted as they are the ones that contain no other symbols besides numbers.

推荐答案

使用grep:

grep -v -E '^[0-9]+$' < source.txt > destination.txt

这篇关于如何删除BASH中仅包含数字的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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