linux - Bash - 删除以数字结尾的行

标签 linux bash

我只需要删除以数字结尾的行(在文本文件中)。

之前:

1987 Robocop
1990 Robocop 2 
1993 Robocop 3 
2014 Robocop

之后:

1987 Robocop
2014 Robocop

最佳答案

既然你引用了我的 favorite movie ,我来回答:

sed '/[ \t][0-9][0-9]*[ \t]*$/d' movies.txt

这意味着:

Delete any line where there is either a space or a tab, followed by at least one digit, then any amount of spaces or tabs at the end of a line.

在 Linux 上有更紧凑的方法来表示这一点,但为了可移植性,我给了您一种比较困难的方法。

关于linux - Bash - 删除以数字结尾的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32318537/

相关文章:

git - 如何检查仓库是否存在?

bash脚本: wildcard expression is not processed as expected

linux - printf 使用 in/bin/bash

java - 如何修复 Gradle 在 Linux 上无法识别 Java 10?

java - Hadoop 堆分配

linux - 在 pi 上流式传输视频的更有效方式

bash - 无法在终端中换行

c - for循环中的fork()执行

linux - 仅返回匹配模式之后的行部分

php - 比较目录状态或散列以获得乐趣和利润的最快方法