Re: tr syntax

From: E Arredondo (atk_at_sbcglobal.net)
Date: 05/27/05


Date: Fri, 27 May 2005 14:53:57 GMT


"Brian K. White" <brian@aljex.com> wrote in message
news:046501c54b96$18014080$6500000a@venti...
>
> ----- Original Message -----
> From: "E Arredondo" <atk@sbcglobal.net>
> Newsgroups: comp.unix.sco.misc
> To: <distro@jpr.com>
> Sent: Wednesday, April 27, 2005 5:48 PM
> Subject: tr syntax
>
>
>> Do you know the right syntax for the TR command to strip characters from
>> a
>> file ?
>>
>>
>> my file looks like this :
>>
>> rfq=ADDRFQ%7ER-050427%3A033325%7ECARQUEST%7E9%7E1.1%7E2005-04-27T12%3A33%3A25.00
>> 0-07%3A00%0D%0ARFQ%7ER-050427%3A033325%7ER-050427%3A033325%7E2005-04-27T12%3A33%
>> 3A25.000-07%3A00%7E0%7E0%7E57603%7Etest%7E654654+test+ave%7E%7E%7Esanta+ana%7ECA
>> %7E92704%7EUS%7E%28714%29+850-1544%7E32423%7ENew+York+DC%7E32+Apple+Lane%7E%7E%7
>> ENew+York%7ENY%7E10010%7EUS%7E%28212%29+212-2122%7E%0D%0ALINE%7ER-050427%3A03332
>> 5%7E1%7ER-050427%3A033325%7EDF01%7EDF01%7E1.0%7EEA%7EFREGHT%7E%0D%0A
>>
>>
>> and I want to change all the %7E for an ~
>>
>> and I've tried
>>
>> cat file.txt | tr "%7E" "~" but only changes the % for an ~ and
>> leaves the 7E.
>>
>> Then I want to change the %0D%0A for a Line feed or carriage return.
>>
>> cat file.txt | tr "%0D%0A" "/012"
>>
>>
>> Thanks
>
> tr can not do that job, for that you want sed, or....
>
> This is a good example of what we mean when we sometimes tell people "tell
> us what you really want" instead of trying to abstract out the part you
> think you need solved out of the real whole problem.
>
> This appears to be url-encoded content, you may be interested to know
> there
> are utilities and code snippets in various languages already designed just
> for the purpose of url en/de-coding. There are a lot of other codes
> besides
> the couple you asked about, and you should really be prepared to decode
> any
> that might appear in the data, including ones that you haven't just
> happened
> to encounter yet.
>
> I found a couple of snippets of c code that do this and made them into
> bare
> bones stand-alone executables.
> http://www.aljex.com/bkw/sco/index.html#urlenc
>
> Unfortunately, your data also includes "+" in place of spaces, which is
> another common url hack, and unfortunately, it wouldn't be safe/sane in my
> opinion to wholesale replace all + with " " (which tr can do) because
> surely
> a "+" is a legitimate character that might appear in the data?
>
> The spaces should have been submitted to the cgi as %20 instead of + in
> the
> first place. By the time you recieve the data above, it's too late for you
> to be able to reliably convert the +'s back to spaces without also
> converting +'s that were supposed to actually be +'s in the data.
>
> Here's a command to use the binary above and tr to decode all the url
> codes
> and convert all +'s to spaces and just hope no + ever comes in as data.
> deurl "$rfq" |tr "+" " "
>
> My guess is you are ultimately getting this data into filepro. You could
> leave off the tr and use xlate in filepro almost as easily. In that case,
> you could decide to only xlate certain fields, leaving the possibility of
> real data +'s in some fields. The tr command will convert every + in the
> record and has no concept of fields.
>
> Brian K. White -- brian@aljex.com -- http://www.aljex.com/bkw/
> +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
> filePro BBx Linux SCO Prosper/FACTS AutoCAD #callahans Satriani
>

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:

------------- start ---------------------
rfq=ADDRFQ%7ER-050523%3A020823%7ECARQUEST%7E9%7E1.1%7E2005-05-23T11%3A08%3A23.00
0-07%3A00%0D%0ARFQ%7ER-050523%3A020823%7ER-050523%3A020823%7E2005-05-23T11%3A08%
3A23.000-07%3A00%7E0%7E0%7E283642%7EATK+North+America%7E3210+S.+Croddy+Way%7E%7E
%7ESanta+Ana%7ECA%7E92704%7EUS%7E%28714%29+850-1544%7E343992%7EJBS+Logistics%7E2
00+Regency+Dr%7E%7E%7EGlendale+Heights%7EIL%7E60139%7EUS%7E630-924-2000%7E%0D%0A
LINE%7ER-050523%3A020823%7E1%7ER-050523%3A020823%7EDF01%7EDF01%7E1.0%7EEA%7EFREG
HT%7E%0D%0A
~
~
~
"cq18821.txt" [Incomplete last line] 1 line, 491 characters
----------- cut here ------------------------

Here's what my cgi script does :

car.cgi----------------------------------
#!/bin/ksh
umask 0
. ./fpsetenv.bat
FILE=/usr2/appl/fpmerge/cq$$.txt
cat > $FILE

echo Content-type: text/plain
echo

.....etc (script keeps doing more things)
----------------------------------------------------

How can I fix this issue with the "Incomplete last line" ?

Thanks so much in advance



Relevant Pages

  • Re: Environment variables and paths
    ... The inbuilt help facility suggests this syntax: ... and how to use executables and their parameters. ... > ok I used the m switch before the path and I get the command is not ... > just give me the correct syntax for my entry in the login script so we ...
    (microsoft.public.win2000.general)
  • Re: .bat from asp.net w/System.Diagnostics.Process?
    ... The results of the script from the command prompt when run from an .aspx are ... The ftp call syntax that I am using allows you to have a text file with all of your ftp connection info in it. ...
    (microsoft.public.dotnet.framework.aspnet)
  • [opensuse] error Output
    ... I have a script that counts the number of files in a certain directory. ... The command I use is: ... What should my syntax be for this line? ... The views expressed in this e-mail are the views of the individual sender and should in no way be construed as the views of the Company. ...
    (SuSE)
  • Re: A question about syntax of the if statement.
    ... I just build tcl/tk and am looking over a tutorial on the language. ... The command is not a special syntax of the language. ... word after the command is evaluated as a script in the same scope as the ...
    (comp.lang.tcl)
  • Re: Problems trying to configure Linux laptop to print to Windows XP shared printer
    ... map to guest = Never ... check password script = ... enumports command = ... ldap delete dn = No ...
    (comp.os.linux.setup)