Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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..

Does -Eo not work with 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) ********

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..

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!

like image 820
linux4fun Avatar asked Mar 18 '23 06:03

linux4fun


1 Answers

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).

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

should work.

Read the man page for details.

like image 102
ci_ Avatar answered Apr 06 '23 08:04

ci_