Re: Loosing price variable only when assigning to variable name



On 2006-08-16, tpscrat@xxxxxxxxx wrote:
I really appreciate all of you guys help. I would be happy to send a
little paypal thanks to the person that can point me in the right
direction with this one.

The thing I don't understand which goes back to my first reply, is that
I have a title and description search using the same methods, and that
works fine. They egrep the data, sed some stuff out of it and echo out
as a variable with no problem. It is only the price field that echo's
blank. But when the exact same price command is used without defining
it as a variable it also works ok. It's just that I need to be able to
assign it to a variable name to call it up later in the script.

Here is my exact script and exact file I'm working on.

get-product-info.sh < Excuse the extra line breaks from the post

Please use shorter lines for scripts. It can be very hard to
determine what the script is supposed to be when the lines wrap.

It is even more apropos in the case of a file which you want to
search with [e]grep, as the command is line oriented. A URL might
have been better than including it here.

It *is* possible to post long lines with Google Groups; I've done
it, but I don't remember exactly how. I think I use my regular
editor (emacs) and pasted the text into the text box. Or perhaps I
used a Firefox extension that allows me to call an external editor
to edit text boxes.

[script reformatted for legibility.]
#######################################
#######################################
#!/bin/bash -e

find . -name "test.html" | while read line;
do
TITLE=`egrep -o -m 1 'color:#FFFFFF;">.*</td>' $line |
sed 's/color:#FFFFFF;">//g' |
sed 's/<\/td>//g' |
sed 's/ //g'`;

No need for sed:

TITLE=`egrep -o -m 1 'color:#FFFFFF;">.*</td>' "$line"`
TITLE=${TITLE#*color:#FFFFFF;\"\>}
TITLE=${TITLE%</td>*}

PRICE=`egrep -o '\$[0-9]+\.[0-9][0-9]' $line | sed 's/\$//g'`;

PRICE=`grep -o '\$[0-9]\+\.[0-9][0-9]' "$line" | sed 's/\$//g'`

You don't need sed:

PRICE=`grep -o '\$[0-9]\+\.[0-9][0-9]' "$line"`
PRICE=${PRICE#?}

DESCR=`egrep -o -m 1 '(<font class=description>)(.*)(<\/font>)' $line |
sed 's/<font class=description>//g' |
sed 's/<\/font>//g' |
sed 's/ > //g'`;

'Nuff sed.

echo -e "$TITLE\t$PRICE\t$DESCR\n";

done
#######################################


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • Re: Reading a text file
    ... What is the exact look of the date in Excel, ... Better to bite the bullet and have the script leverage EXCEL to extract the ... manually exporting a csv file. ... back into the spread sheet as to when it sent the email notification. ...
    (microsoft.public.scripting.wsh)
  • Need Help with Call Shell("cmd /K netstat") Function!!!
    ... I have found a better solution using a script based FTP ... using the Command Prompt the "Call Shell" function to be exact. ... however come into a problem with using the Call Shell function. ...
    (microsoft.public.excel.programming)
  • Re: Remove and Add Printer Script
    ... Then rerun the script. ... It will crash at the exact ... turn error checking back on ... I tried that and I get the same exact result. ...
    (microsoft.public.scripting.vbscript)
  • Re: Simple shell question
    ... I'm trying to write a script to start my J2EE server so I don't ... "exact lines" ?? ... "ik _heb_ niets tegen Microsoft, ...
    (alt.os.linux.suse)
  • Re: bad gnome-terminal or bad script?
    ... >> I just tried the same script with telnet instead of SSH. ... The exact same ... >> from a console, it behaves beautifully with none of the bad behavior I ...
    (Fedora)