sed/awk insert - help gurus
sed/awk insert - help gurus
am 15.10.2007 08:43:09 von bob_smithley
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.
Re: sed/awk insert - help gurus
am 15.10.2007 09:48:57 von cichomitiko
bob_smithley@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 "${$(
\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
Re: sed/awk insert - help gurus
am 15.10.2007 09:51:17 von bob_smithley
thank you very much Dimitre, the sed solution is perfect!
thanks again :)
Re: sed/awk insert - help gurus
am 15.10.2007 10:00:53 von cichomitiko
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 "${$(
[...]
print -r "${$(
(the l option is unnecessary)
Dimitre
Re: sed/awk insert - help gurus
am 15.10.2007 12:47:07 von bob_smithley
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
Re: sed/awk insert - help gurus
am 15.10.2007 14:08:39 von bob_smithley
I am getting closer:
sed -e "s/\x00[0-9]\x00[0-9]\x00[0-9]\x00\.
\x00[0-9]\x00[0-9]\x00[0-9]\x00.\x00[0-9]\x00[0-9]\x00.\x00[ 0-9]\x00[0-9]\x00[0-9]/
%NEWIP%/g" myfile
will match an IP like 134.187.58.155 in the unicode file
but how can I make sure all IPs are matched?
e..g 10.22.333.4
Re: sed/awk insert - help gurus
am 15.10.2007 15:06:05 von Ed Morton
bob_smithley@yahoo.com wrote:
> I am getting closer:
>
> sed -e "s/\x00[0-9]\x00[0-9]\x00[0-9]\x00\.
> \x00[0-9]\x00[0-9]\x00[0-9]\x00.\x00[0-9]\x00[0-9]\x00.\x00[ 0-9]\x00[0-9]\x00[0-9]/
> %NEWIP%/g" myfile
>
> will match an IP like 134.187.58.155 in the unicode file
>
> but how can I make sure all IPs are matched?
>
> e..g 10.22.333.4
>
Use an RE interval to specify 1 to 3 digits:
\(\x00[0-9]\)\{1,3\}\x00.
instead of exactly 3 digits:
\x00[0-9]\x00[0-9]\x00[0-9]\x00.
Regards,
Ed.
Re: sed/awk insert - help gurus
am 15.10.2007 15:35:54 von bob_smithley
thanks for that, much appreciated :)