APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > News Posts > converting url-encoded
Printer Friendly Version




News Group Posts

converting url-encoded



From: "Brian K. White" <brian@aljex.com>
Subject: Re: tr syntax
Date: 31 May 2005 16:42:07 -0400
Message-ID: <08d001c56621$306386b0$6b00000a@venti> 
References: <FMTbe.8686$J12.2080@newssvr14.news.prodigy.com>
<046501c54b96$18014080$6500000a@venti>
<9wGle.2067$rY6.354@newssvr13.news.prodigy.com>
<119ejq3b7mr18c6@corp.supernews.com>
<6g0ne.624$IE7.267@newssvr21.news.prodigy.com> ----- Original Message ----- From: "E Arredondo" <atk@sbcglobal.net> Newsgroups: comp.unix.sco.misc Sent: Tuesday, May 31, 2005 12:27 PM Subject: Re: tr syntax


>
> "John DuBois" <spcecdt@armory.com> wrote in message 
> news:119ejq3b7mr18c6@corp.supernews.com...
>> In article <9wGle.2067$rY6.354@newssvr13.news.prodigy.com>,
>> E Arredondo <atk@sbcglobal.net> wrote:
>>>I can't sed my file because I found out that, after I receive the data 
>>>from
>>>a http call and then *cat*ing it to a file from a cgi-bin script it makes 
>>>a
>>>file like this whit the message "Incomplete Last line" and neither *tr* 
>>>or
>>>*sed* would work unless I *vi* the file and then save the file to get rid 
>>>of
>>>that message "Imcomplete last line", then tr and sed will work fine:
>>>How can I fix this issue with the "Incomplete last line" ?
>>
>> tr should work fine.  sed does insist on a trailing newline.  You can do:
>>
>> { cat file; echo ""; } | sed ...
>>
>> to append a newline to its input.  Or use awk, which doesn't have this 
>> problem;
>> replace
>>
>>    sed 's/foo/bar/'
>>
>> with
>>
>>    awk '{sub(/foo/,"bar")}1'
>>
>> John
>> -- 
>
> My script is working now but I was just wondering if there's a way to 
> compress the sed into 1 line to make it simpler to save some milliseconds 
> or maybe seconds of processing time, Does it accepts semi colons or commas 
> between searches ?, here's what my final script looks like,  :
>
> -------------begin here --------------------
> FILE=/usr2/appl/fpmerge/cq$$.txt
> FILE2=/usr2/appl/fpmerge/cqa$$.txt
> cat > $FILE
> echo >> $FILE
>
> sed -e "s/%7E/\~/g" < $FILE > $FILE2
> sed -e "s/%3A/\:/g" < $FILE2 > $FILE
> sed -e "s/%0D%0A/\|/g" < $FILE > $FILE2    # this will let tr down below 
> change all |'s for LF's
> sed -e "s/+/ /g" < $FILE2 > $FILE
> sed -e "s/%28/\(/g" < $FILE > $FILE2
> sed -e "s/%29/\)/g" < $FILE2 > $FILE
> cat $FILE | tr "|" "[\012*]" > $FILE2
>
> ------------cut here-------------

Yes they can all be combined .
I would not use sed for this though because you'll be forever adding odd new 
codes as you encounter them for the first time.
Instead use a tool that is designed to do the job you really need done, 
which is not to convert %7E to ~, but to decode url-encoding, which is a 
potential 127 or 255 such codes.

As long as the file is 4k or less, try this

-------------begin here --------------------
FILE=/usr2/appl/fpmerge/cq$$.txt
FILE2=/usr2/appl/fpmerge/cqa$$.txt
cat > $FILE
deurl `cat $FILE` |tr -d "\r" >$FILE2

get deurl from http://www.aljex.com/bkw/sco/#urlenc
------------cut here-------------














If you fetched it a few weeks ago when you started the thread, get a fresh 
copy.
Just after posting about here to you originally, I updated it so it can 
accept 4k of input, up from only 255 bytes before.

If 4k isn't enough then the C code really needs to be changed so that it 
works like cat. taking either a filename on the commandline, or taking in 
data on stdin.

I'm not sure how far we can increase the buffer for taking in actual data as 
one big command line like it is now.
It probably depends on the shell, and ksh does allow a lot. I tested it one 
time but don't remember what it was but it was far more than I expected.

It's easy to try it anyways. for me to tweak the number and make a new 
binary is trivial so try it and maybe bumping it up some more will be good 
enough.

If some kind soul will look at the tar referenced above, the source is in 
there, and make a cat-like version of it?
I'm not a c coder.
I could probably manange this, It's probably not even hard t by taking gnu 
cat and dropping in this one big function.
But I'm just busy with other stuff and it's working for what I need as it 
is, so I haven't the motivation.
But it really should get done.

-- 
Brian K. White  --  brian@aljex.com  --  http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx  Linux SCO  Prosper/FACTS AutoCAD  #callahans Satriani


If this page was useful to you, please click to help others find it:  

Your +1's can help friends, contacts, and others on the web find the best stuff when they search.

1 comment



Click here to add your comments





Tue Apr 18 20:49:33 2006:   trantor


This is BKW

The new improved, general purpose, cat-like urlenc/urldec has been coded up by a kind soul and the source & binaries are here:
http://www.aljex.com/bkw/sco#urldec
and here
ftp://pcunix.com/bkw/urldec.tar.bz2

It pretty much handles all likely situations we could think of, including:
* encode/decode string from commandline
* encode/decode from file given on commandline
* encode/decode to/from stdin/stdout
* do/don't encode/decode trailing newline on input
* do/don't append newline

Includes a nice man page and a -h option for help.
And the source compiles on linux and freebsd out of the box if you get the source from either of the sites above instead of the authors site. The Makefile in the original source (Acreditation link on my page above) has a few site & user specific glitches I removed.


Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

g_face.jpg

This post tagged:

       - Filepro
       - SED
       - Scripting
       - Shell




Unix/Linux Consultants

Skills Tests

Guest Post Here