linux - 从文件中删除特定数据

标签 linux bash

我有包含 IP 列表的文件。在这些 IP 中,我想删除 10.0.1.x 系列的 IP。

所以要检查我使用以下命令的那些 IP

grep -F "10.0.1." IPList.txt

但是如何从 IPList.txt 中删除这些 IP,因为我必须提供此 IPList.txt 文件作为另一个脚本的输入。

最佳答案

一个可能的选择是使用 grep -vGNU Grep 2.23 man page部分地说,

-v
--invert-match

    Invert the sense of matching, to select non-matching lines.
    (-v is specified by POSIX.)

有点像

grep -v "10.0.1." < IPList.txt > IPList-nolocal.txt

这会将 IPList.txt 复制到 IPList-nolocal.txt,排除匹配 10.0.1 的任何行。

如果您想在运行时查看输出,可以使用 tee command (链接的维基百科文章开头通常用于拆分程序的输出,以便它既可以显示又可以保存在文件中)

grep -v "10.0.1." < IPList.txt | tee IPList-nolocal.txt

关于linux - 从文件中删除特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35908637/

相关文章:

c - linux 中的 toupper 和 tolower 函数使用 XOR 按位运算

linux - elasticsearch 中的 Gradle 问题

c++ - 如何跟踪消息响应时间和重传

bash - 使用 AWK 过滤掉具有数值范围的列

arrays - 理解代码({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1 })

c++ - 哪个浏览器插件框架适用于 Linux 中的所有浏览器

c - 这个shellcode又让人头疼

linux - 如何确定某个文件中的每一行是否相同?

linux - crontab 用于调度 shell 脚本

linux - 有关创建 Ubuntu 软件包的 .sh 脚本的一些信息?