如何在 linux shell 中使用正则表达式从文件中提取 IP 地址? [英] How do you extract IP addresses from files using a regex in a linux shell?

查看:40
本文介绍了如何在 linux shell 中使用正则表达式从文件中提取 IP 地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在linux shell中通过regexp提取文本部分?比方说,我有一个文件,其中每一行都是一个 IP 地址,但位于不同的位置.使用常见的 Unix 命令行工具提取这些 IP 地址的最简单方法是什么?

How to extract a text part by regexp in linux shell? Lets say, I have a file where in every line is an IP address, but on a different position. What is the simplest way to extract those IP addresses using common unix command-line tools?

推荐答案

你可以使用 grep 把它们拉出来.

You could use grep to pull them out.

grep -o '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}' file.txt

这篇关于如何在 linux shell 中使用正则表达式从文件中提取 IP 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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