From: bob_smithley on
O sed gurus...

I have a text file that contains an IP address.

can be:

10.34.125.23

or 201.2.244.5

etc.

I would like to insert \x00 before each character.

e.g. so 10.34.125.23 becomes

\x001\x000\x00.\x003\x004\x00.\x001\x002\x005\x00.\x002\x003

I have tried sed and awk but no luck.. :( Any suggestions will be most
appreciated.

From: Radoulov, Dimitre on
bob_smithley(a)yahoo.com wrote:
[...]
> I have a text file that contains an IP address.
>
> can be:
>
> 10.34.125.23
>
> or 201.2.244.5
>
> etc.
>
> I would like to insert \x00 before each character.
>
> e.g. so 10.34.125.23 becomes
>
> \x001\x000\x00.\x003\x004\x00.\x001\x002\x005\x00.\x002\x003
[..]

zsh:

zsh 4.3.4% cat textfile
10.34.125.23
201.2.244.5
zsh 4.3.4% print -rl "${$(<textfile)///\x00}"
\x001\x000\x00.\x003\x004\x00.\x001\x002\x005\x00.\x002\x003\x00
\x002\x000\x001\x00.\x002\x00.\x002\x004\x004\x00.\x005

GNU Awk:

awk '$1=$1' FS="" OFS="\\\x00" textfile


sed:

sed 's/./\\x00&/g' textfile


Dimitre
From: bob_smithley on
thank you very much Dimitre, the sed solution is perfect!

thanks again :)

From: Radoulov, Dimitre on
Radoulov, Dimitre wrote:
[...]
>> I would like to insert \x00 before each character.
>>
>> e.g. so 10.34.125.23 becomes
>>
>> \x001\x000\x00.\x003\x004\x00.\x001\x002\x005\x00.\x002\x003
> [..]
>
> zsh:
>
> zsh 4.3.4% cat textfile
> 10.34.125.23
> 201.2.244.5
> zsh 4.3.4% print -rl "${$(<textfile)///\x00}"
[...]


print -r "${$(<textfile)///\x00}"

(the l option is unnecessary)


Dimitre
From: bob_smithley on
another problem (I am not good with sed....)

I have a unicode file with an IP address. e.g. 10.34.125.23

I am trying to work out a way to replace it a with a variable(e.g.
%NEWIP%)

because the file is unicode, I have to search for this string:

\x001\x000\x00.\x003\x004\x00.\x001\x002\x005\x00.\x002\x003

and then replace it with %NEWIP%.

I have been trying to get the regular expression correct, but it's not
working.

I need to search for any valid IP address in the unicode file e.g.


\x001\x000\x00.\x003\x004\x00.\x001\x002\x005\x00.\x002\x003
(10.34.125.23)

or

\x002\x000\x001\x00.\x002\x00.\x002\x004\x004\x00.\x005 (201.2.244.5)

thaks again