From: bob_smithley on 15 Oct 2007 02:43 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 15 Oct 2007 03:48 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 15 Oct 2007 03:51 thank you very much Dimitre, the sed solution is perfect! thanks again :)
From: Radoulov, Dimitre on 15 Oct 2007 04:00 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 15 Oct 2007 06:47 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
|
Next
|
Last
Pages: 1 2 Prev: Error with using Imagemagick convert from a shell script Next: sed replace issue |