简体   繁体   English

Grep在OpenBSD中对Linux的表现不同。无法让命令工作

[英]Grep behaving differently in OpenBSD to Linux. Cannot get command working

So basically what this command does is securely connect to a web domain to grab my external IP address, this works flawlessly on a Linux Debian system, but it is not working right on my OpenBSD system. 所以这个命令基本上是安全地连接到一个Web域来获取我的外部IP地址,这在Linux Debian系统上完美运行,但它在我的OpenBSD系统上无法正常工作。 Curl command works fine, however something is up with the Grep command as it just isn't grabbing the IP that curl is piping to it.. Curl命令工作正常,但是Grep命令有些问题,因为它只是没有抓住卷曲管道到它的IP。

Does -Eo not work with OpenBSD? 是 - 是不是可以使用OpenBSD? I cannot tell with the man page.. 我无法用手册页告诉我..

USERAGENT="Mozilla/4.0"
WEB_LOCATION="https://duckduckgo.com/?q=whats+my+ip"

curl -s --retry 3 --max-time 5 -tlsv1.2 --user-agent $USERAGENT $WEB_LOCATION | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'

******* RESOLVED (Kinda) ******** ******* RESOLVED(Kinda)********

I worked out that for some reason this particular pattern : 我通过某种原因计算出这种特殊模式:

grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'

was not working on OpenBSD, but this long version does.. 没有在OpenBSD上工作,但这个长版本确实如此......

grep -Eo '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'

Why this is the case is very confusing, as the first search pattern works fine on all the versions of Debian Linux I have used! 为什么会出现这种情况非常令人困惑,因为第一个搜索模式在我使用过的所有Debian Linux版本上运行良好!

The issue is with the word boundary patterns in your regexp, which are [[:<:]] and [[:>:]] in OpenBSD but \\< and \\> respectively in Debian (and possibly other Linux distributions). 问题在于regexp中的边界模式,在OpenBSD中是[[:<:]][[:>:]] ,而在Debian(以及可能的其他Linux发行版)中分别是\\<\\>

grep -Eo '[[:<:]][[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}[[:>:]]'

should work. 应该管用。

Read the man page for details. 阅读手册页了解详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM