Passing blank spaces, |, % to my CGI in sh

Hi,
  When I pass blank spaces,%, |, etc
from my web page to my cgi it comes with
extra characters, do you know how to
avoid them?. I am using sh in UNIX (I can not
use Perl).

Thanks.
LVL 1
aacostaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
What do you mean extra characters?
Do they show up as +, %25, %72, respectively?
Do you want to translate them back to space, %, | ?
Can you use awk?
0
aacostaAuthor Commented:
yes,
Thats is what I want.
In this moment, the script shows me + as blank spaces, %25, %72, etc.

I need to translate this kind of characters to "normal" characters and so on (I think there are more than three "special characters")

Yes, I can use awk.

Thanks!.
0
aacostaAuthor Commented:
Adjusted points to 216
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

aacostaAuthor Commented:
It is urgent!.
I can use awk and almost any command of the shell (sh).
I need to receive a form (four lines) correctly in my cgi script.

I have just adjusted the points to 516!!.


0
ozoCommented:
nawk 'BEGIN{FS="%";ORS=""}{print $1; for( i=2; i<=NF; i++ ){printf "%c",system("ksh \"exit $((16#" substr($i,0,2) "))\""); print substr($i,3); } print "\n"}'
0
aacostaAuthor Commented:
Hi,
 I tried to use the statement you gave me but it did not worked.
The string that comes from my web page is called USERNAME and contains the following (this is an example, of course it changes for any character):

USERNAME=ale+acosta+alamo&OLD_PASSWORD=123456&NEW_PASSWORD=abc&CONF_NEW_PASSWORD=abc

(this is the value I obtain from echo $USERNAME in my cgi).

I used $1 and $USERNAME in the command but did not work either.

Thanks.
0
ozoCommented:
echo $USERNAME | tr '+' ' ' | nawk 'BEGIN{FS="%";ORS=""}{print $1; for( i=2; i<=NF; i++ ){printf "%c%s",system("ksh exit $((16#" substr($i,0,2) "))"),substr($i,3); } print RS }'
0
ozoCommented:
echo $USERNAME | tr '+' ' ' | nawk 'BEGIN{FS="%";ORS=""}{print $1; for( i=2;i<=NF; i++ ){printf "%c%s",system("ksh \"exit $((16#" substr($i,0,2) "))\""),substr($i,3);} print RS }'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aacostaAuthor Commented:
It almost worked!. The blank spaces pass correctly, if I pass a variable with %, |, ?,;, etc there appear just white square (). Why?

Thanks again.

Ale,-
0
aacostaAuthor Commented:
Great! and thanks. I was trying the firts one.

Ale,-
0
aacostaAuthor Commented:
Thanks.
0
aacostaAuthor Commented:
Hi again, is there a way to substitude nawk by awk?, I tried to do it and did not work. In addition I tried gawk.

The problem is that I am now in a Linux box.

Sorry again.

Alejandro
0
ozoCommented:
it would be easiest if you could use Perl...
0
aacostaAuthor Commented:
Yes I know.
I would like to use perl but the code is already done in a shell script and now we want to adapt it to the web(sorry).
Can I substitude the nawk in your command with awk some way?. I tried to do it but did not work.

Thks!.-
0
ozoCommented:
shell scripts can call perl as easily as they can call awk or nawk.
It can still be done with awk, but it gets a bit messy:

awk 'BEGIN{FS="%";}{print "echo -n " $1; for( i=2;i<=NF; i++ ){print "echo $((16#" substr($i,0,2) ")) | awk \\{printf\\\"%c\\\",\\$1\\}"; print "echo -n " substr($i,3);} }' | ksh
0
aacostaAuthor Commented:
Hi, again.
I tried the command you told me and did not work.

In addition I tried:

echo $USERNAME|awk 'BEGIN{FS="%";}{print "echo -n " $1; for( i=2;i<=NF; i++ ){print "echo $((16#" substr($i,0,2) ")) | awk \\{printf\\\"%c\\\",\\$1\\}"; print "echo -n " substr($i,3);} }' | ksh

And did not work :-(

In addition I tried something like:

echo $USERNAME | tr '+' ' ' | awk 'BEGIN{FS="%";}{print "echo -n " $1; for( i=2;i<=NF; i++ ){print "echo $((16#" substr($i,0,2) ")) | awk \\{printf\\\"%c\\\",\\$1\\}"; print "echo -n " substr($i,3);} }' | ksh

And did not work neither.

Where do I have to use $USERNAME (the var from the web page) in your command (remember I am newbie).

If you like we can call perl from the shell script but I dont want to create a new file.

Sorry and thanks again.
0
ozoCommented:
I'd ask what you get from just
echo $USERNAME | tr '+' ' ' | awk 'BEGIN{FS="%";}{print "echo -n " $1; for(i=2;i<=NF; i++ ){print "echo $((16#" substr($i,0,2) ")) | awk \\{printf\\\"%c\\\",\\$1\\}"; print "echo -n " substr($i,3);} }'
without the | ksh
but if you can call perl from the shell script, it may be easier to just use
echo $USERNAME | perl -pe 'tr/+/ /;s/%(\w\w)/pack"H2",$1/ge'
0
aacostaAuthor Commented:
Hi, The first command did not work, my vars were empty.

The second one (with perl) worked perfectly!.

Really thanks again.

Alejandro Acosta A.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.