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

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

问题描述

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

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

推荐答案

=http://unixhelp.ed.ac.uk/CGI/man-cgi?grep =nofollow noreferrer> 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中使用regex从文件中提取IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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