escaping "." in ip address
I need to escape the periods in some ip addresses. I need xc=111.111.111.111 to become 111\\.111\\.111\\.111 sed appears (or not) to be the proper utility but I cannot get the correct syntax. tks -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet oftc What sort of day was it? A day like all days, filled with those events that alter and illuminate our times...
Op donderdag 17 maart 2022 15:08:28 CET schreef Patrick Shanahan:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
tks
IP=111.111.111.111 xc=`echo "${IP//./}" ` -- Gertjan Lettink a.k.a. Knurpht openSUSE Board openSUSE Forums Team
On 17.03.22 15:16, Knurpht-openSUSE wrote:
Op donderdag 17 maart 2022 15:08:28 CET schreef Patrick Shanahan:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
tks
IP=111.111.111.111 xc=`echo "${IP//./}" `
ITYM ${IP//./\\\\.} and ... no need for the echo: IP=${IP//./\\\\.} Josef -- SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
* Josef Moellers
On 17.03.22 15:16, Knurpht-openSUSE wrote:
Op donderdag 17 maart 2022 15:08:28 CET schreef Patrick Shanahan:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
tks
IP=111.111.111.111 xc=`echo "${IP//./}" `
ITYM ${IP//./\\\\.} and ... no need for the echo: IP=${IP//./\\\\.}
tks much, IP={IP//./\\\\.} is perfect -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet oftc What sort of day was it? A day like all days, filled with those events that alter and illuminate our times...
Patrick Shanahan wrote:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
In which context, Patrick? there are places where you need three backslashes, even four. -- Per Jessen, Zürich (15.4°C)
Op donderdag 17 maart 2022 15:18:06 CET schreef Per Jessen:
Patrick Shanahan wrote:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
In which context, Patrick? there are places where you need three backslashes, even four. Sorry, read wrong
-- Gertjan Lettink a.k.a. Knurpht openSUSE Board openSUSE Forums Team
* Per Jessen
Patrick Shanahan wrote:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
In which context, Patrick? there are places where you need three backslashes, even four.
grep from bash control line grep 111\\.111\\.111\\.111 tks -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet oftc What sort of day was it? A day like all days, filled with those events that alter and illuminate our times...
Patrick Shanahan wrote:
* Per Jessen
[03-17-22 10:20]: Patrick Shanahan wrote:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
In which context, Patrick? there are places where you need three backslashes, even four.
grep from bash control line grep 111\\.111\\.111\\.111
tks
Two options - a) put the regex in quotes, then you need only one backslash. b) without qoutes, you need three backslashes. -- Per Jessen, Zürich (11.8°C)
* Per Jessen
Patrick Shanahan wrote:
* Per Jessen
[03-17-22 10:20]: Patrick Shanahan wrote:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
In which context, Patrick? there are places where you need three backslashes, even four.
grep from bash control line grep 111\\.111\\.111\\.111
tks
Two options -
a) put the regex in quotes, then you need only one backslash. b) without qoutes, you need three backslashes.
I have presented, IP=${IP//./\\\\.} which works perfectly, but I didn't explain sufficiently to you my requirement. I need to grep $IP a file containing ip addresses and need to ensure the dots appear in the correct location as: grep 111.11.111.1 will match 111.1.1.1 without escaping the dot position this all but solves my need. I would also like to be able to drop the 4th quad and/or the 3rd and 4th. Is that also possible? I am trying to automagic blocking errant ip's using ipset and logs of sites trying to relay mail or gain unpermitted system access. I currently have a list of >10000 sites or ranges of sites blocked using above criteria. built over some years. and I realize that many are blocking ip4 sites that change address occasionally. ps: since some years ago moving ssh to a high port, I have a very low count of ssh attempts. -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet oftc What sort of day was it? A day like all days, filled with those events that alter and illuminate our times...
On 2022-03-17 18:11, Patrick Shanahan wrote:
this all but solves my need. I would also like to be able to drop the 4th quad and/or the 3rd and 4th.
I use this: $ cat ~/script/grepipnumber #!/bin/sh grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
Is that also possible?
Absolutely $ echo 1.1.1.1 | grepipnumber | awk -F. '{print $1"."$2}' 1.1 Often I need to append the net-part. Like so. $ echo 1.1.1.1 | grepipnumber | awk -F. '{print $1"."$2"."$3".0/24"}' 1.1.1.0/24 -- /bengan
* Bengt Gördén
On 2022-03-17 18:11, Patrick Shanahan wrote:
this all but solves my need. I would also like to be able to drop the 4th quad and/or the 3rd and 4th.
I use this: $ cat ~/script/grepipnumber
#!/bin/sh
grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
Is that also possible?
Absolutely $ echo 1.1.1.1 | grepipnumber | awk -F. '{print $1"."$2}' 1.1
Often I need to append the net-part. Like so.
$ echo 1.1.1.1 | grepipnumber | awk -F. '{print $1"."$2"."$3".0/24"}' 1.1.1.0/24
tks, when I get matches for the first three quads, I ban 0/24. and from china for any I ban $1.$2.0/16 I figure legitimate china attempts will be via VPN. -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet oftc What sort of day was it? A day like all days, filled with those events that alter and illuminate our times...
On 3/17/22 17:46, Patrick Shanahan wrote:
* Per Jessen
[03-17-22 10:20]: Patrick Shanahan wrote:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
In which context, Patrick? there are places where you need three backslashes, even four.
grep from bash control line grep 111\\.111\\.111\\.111
Another way: use `grep -F`: -F, --fixed-strings PATTERNS are strings (no need to escape the '.' in fixed strings) Have a nice day, Berny
* Bernhard Voelker
On 3/17/22 17:46, Patrick Shanahan wrote:
* Per Jessen
[03-17-22 10:20]: Patrick Shanahan wrote:
I need to escape the periods in some ip addresses.
I need xc=111.111.111.111 to become 111\\.111\\.111\\.111
sed appears (or not) to be the proper utility but I cannot get the correct syntax.
In which context, Patrick? there are places where you need three backslashes, even four.
grep from bash control line grep 111\\.111\\.111\\.111
Another way: use `grep -F`:
-F, --fixed-strings PATTERNS are strings
(no need to escape the '.' in fixed strings)
a *better* solution, tks -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet oftc What sort of day was it? A day like all days, filled with those events that alter and illuminate our times...
Patrick, et al -- ...and then Patrick Shanahan said... % % I need to escape the periods in some ip addresses. ... % % sed appears (or not) to be the proper utility but I cannot get the correct % syntax. In what context and under what environment? I saw some very bash-y code going by, but that presumes a loss of portability is acceptable -- and that you aren't doing this inside something else in the first place. % % % tks % -- % (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri HTH :-D -- David T-G See http://justpickone.org/davidtg/email/ See http://justpickone.org/davidtg/tofu.txt
participants (7)
-
Bengt Gördén
-
Bernhard Voelker
-
David T-G
-
Josef Moellers
-
Knurpht-openSUSE
-
Patrick Shanahan
-
Per Jessen