From: Sashi on
All, I have a file with prices, from which I need to drop the '$'.
I'm trying to use sed to do this:
echo $297.00 | sed 's/\$\(\d\{1,\}\.\d\{1,\}\)/\1/g'

Logic: find a $, followed by one or more digits, followed by a .
followed by one or more digits and remove the $.

However, this example outputs 97.00 and is dropping the '2'.
What am I missing here?

Thanks,
Sashi
From: Glenn Jackman on
At 2008-06-23 03:43PM, "Sashi" wrote:
> All, I have a file with prices, from which I need to drop the '$'.
> I'm trying to use sed to do this:
> echo $297.00 | sed 's/\$\(\d\{1,\}\.\d\{1,\}\)/\1/g'
>
> Logic: find a $, followed by one or more digits, followed by a .
> followed by one or more digits and remove the $.
>
> However, this example outputs 97.00 and is dropping the '2'.
> What am I missing here?

That $2 is empty (hint, try just `echo $297.00` without the pipe)

echo '$297.00' | sed 's/\$\([0-9]\+\.[0-9]\+\)/\1/g'

--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
From: Dave Kelly on
On Jun 23, 2:43 pm, Sashi <small...(a)gmail.com> wrote:
> All, I have a file with prices, from which I need to drop the '$'.
> I'm trying to use sed to do this:
> echo $297.00 | sed 's/\$\(\d\{1,\}\.\d\{1,\}\)/\1/g'
>
> Logic: find a $, followed by one or more digits, followed by a .
> followed by one or more digits and remove the $.
>
> However, this example outputs 97.00 and is dropping the '2'.
> What am I missing here?
>
> Thanks,
> Sashi

CFAJ sent me this a couple of years ago with I had a paypal
receipt with a dollar sign in it.

Since the only hex you are likely to encounter in the sections you
need is =24, you can first pipe the file through sed:

sed 's/=24/$/g'

Or, use bash's search and replace expansion:

total=${total//=24/$}
shipping=${shipping//=24/$}

Come to think of it, I'd just remove it altogether:

sed 's/=24//g'

total=${total//=24/}
shipping=${shipping//=24/}
From: Dave B on
Sashi wrote:

> All, I have a file with prices, from which I need to drop the '$'.
> I'm trying to use sed to do this:
> echo $297.00 | sed 's/\$\(\d\{1,\}\.\d\{1,\}\)/\1/g'

\d is usually a Perl thing, and surely not something standard sed recognizes.

> Logic: find a $, followed by one or more digits, followed by a .
> followed by one or more digits and remove the $.

echo '$297.00' | sed 's/\$\([[:digit:]]\{1,\}\.[[:digit:]]\{1,\}\)/\1/g'

You could probably use [0-9] instead of [[:digit:]]

--
echo 0|sed 's909=oO#3u)o19;s0#0ooo)].O0;s()(0bu}=(;s#}#.1m"?0^2{#;
s)")9v2@3%"9$);so%op]t(p$e#!o;sz(z^+.z;su+ur!z"au;sxzxd?_{h)cx;:b;
s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*#.*\6.*\2.*\)/\5\3\1\7/;
tb'|awk '{while((i+=2)<=length($1)-18)a=a substr($1,i,1);print a}'
From: Sashi on
On Jun 24, 3:20 am, Dave B <da...(a)addr.invalid> wrote:
> \d is usually a Perl thing, and surely not something standard sed recognizes.
That's what I was missing. Thanks for pointing it out!
Sashi