Re: Loosing price variable only when assigning to variable name
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Wed, 16 Aug 2006 19:49:11 -0400
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
.
- Follow-Ups:
- References:
- Loosing price variable only when assigning to variable name
- From: tpscrat
- Re: Loosing price variable only when assigning to variable name
- From: Bill Marcum
- Re: Loosing price variable only when assigning to variable name
- From: tpscrat
- Re: Loosing price variable only when assigning to variable name
- From: Chris F.A. Johnson
- Re: Loosing price variable only when assigning to variable name
- From: tpscrat
- Loosing price variable only when assigning to variable name
- Prev by Date: Re: nohup and sourcing
- Next by Date: Re: nohup and sourcing
- Previous by thread: Re: Loosing price variable only when assigning to variable name
- Next by thread: Re: Loosing price variable only when assigning to variable name
- Index(es):
Relevant Pages
|