On Feb 8, 4:54 am, contracer <
contrace...@gmail.com> wrote:
> How could I replace all spaces in a file with % character, usind "for" loop ?
Why does it necessarily have to use the "for" loop; isn't the looping
flow-of-control code up to you and your particular implementation?
(Actually, the "while" or "until" loop should be more pertainent....)
Are you talking about percent encoding? (Probably not). This
code fragment should show more light on the technique:
From the Kornshell FAQ at
http://kornshell.com/doc/faq.html:
Q25. How can I convert %XX values to ascii?
A25. You can convert this to a sequence of ANSI C strings and
then eval that string, for example suppose the variable 'foo' contains
%XX strings, then:
eval print -r -- "\$'${foo//'%'@(??)/'\x\1"'\$'"}'"
... will print out the string in ascii.
The above uses ksh version 1993 or newer features. If you want
a CGI / URL encoding/unencoding function in shell, there are many
to be found, including one from the author of kornshell:
http://www2.research.att.com/~gsf/download/ksh/scripts/cgi-lib.ksh
http://www2.research.att.com/~gsf/download/ksh/scripts/dump-cgi.ksh
... and others:
ftp://ftp.armory.com/pub/lib/ksh/cgi
http://cgd.sdf-eu.org/a/libs/sh/cgi.sh
http://www.mtxia.com/fancyIndex/Tools/Scripts/Korn/Functions/cgiparse.{html,shtml,txt}
=Brian