Parse and Replace

This is a discussion on Parse and Replace within the awk forums in Programming Languages category; Input: Uploads today: <span style="font-weight:bold;">14.582</span></div> Output: 14582 # awk -F"[<>]+" '/Uploads\ today:/ {print $(NF-3)}' | sed 's/\.//' 14582 Can we only use AWK to change "14.582" to "14582"?...

Go Back   Application Development Forum > Programming Languages > awk

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-14-2008, 06:15 PM
dnlchen@gmail.com
Guest
 
Default Parse and Replace

Input:

Uploads today: <span style="font-weight:bold;">14.582</span></div>

Output: 14582

# awk -F"[<>]+" '/Uploads\ today:/ {print $(NF-3)}' | sed 's/\.//'
14582

Can we only use AWK to change "14.582" to "14582"?
Reply With Quote
  #2  
Old 08-14-2008, 07:48 PM
Janis Papanagnou
Guest
 
Default Re: Parse and Replace

dnlchen@gmail.com wrote:
> Input:
>
> Uploads today: <span style="font-weight:bold;">14.582</span></div>
>
> Output: 14582
>
> # awk -F"[<>]+" '/Uploads\ today:/ {print $(NF-3)}' | sed 's/\.//'
> 14582
>
> Can we only use AWK to change "14.582" to "14582"?


You just want to avoid the sed command?

awk -F"[<>]+" '/Uploads today:/ {x=$(NF-3); gsub(/\./,"",x); print x}'


Janis
Reply With Quote
  #3  
Old 08-17-2008, 11:28 AM
Hermann Peifer
Guest
 
Default Re: Parse and Replace

On Aug 15, 12:15*am, dnlc...@gmail.com wrote:
> Input:
>
> Uploads today: <span style="font-weight:bold;">14.582</span></div>
>
> Output: 14582
>
> # awk -F"[<>]+" '/Uploads\ today:/ {print $(NF-3)}' | sed 's/\.//'
> 14582
>
> Can we only use AWK to change "14.582" to "14582"?


Just to add another option:

awk -F'[<>]' '/Uploads\ today:/ {print $3 * 1000}'
Reply With Quote
  #4  
Old 09-11-2008, 03:12 PM
Ed Morton
Guest
 
Default Re: Parse and Replace



On 8/14/2008 5:15 PM, dnlchen@gmail.com wrote:
> Input:
>
> Uploads today: <span style="font-weight:bold;">14.582</span></div>
>
> Output: 14582
>
> # awk -F"[<>]+" '/Uploads\ today:/ {print $(NF-3)}' | sed 's/\.//'
> 14582
>
> Can we only use AWK to change "14.582" to "14582"?


awk -F"[<>]+" '/Uploads\ today/{ sub(/\./,""); print $(NF-3) }'

or, if we're playing golf:

awk '/Uploads\ today/ && gsub(/[^0-9]/,"")'

Regards,

Ed.

Reply With Quote
  #5  
Old 09-11-2008, 07:14 PM
Grant
Guest
 
Default Re: Parse and Replace

On Thu, 11 Sep 2008 14:12:20 -0500, Ed Morton <morton@lsupcaemnt.com> wrote:

>
>
>On 8/14/2008 5:15 PM, dnlchen@gmail.com wrote:
>> Input:
>>
>> Uploads today: <span style="font-weight:bold;">14.582</span></div>
>>
>> Output: 14582
>>
>> # awk -F"[<>]+" '/Uploads\ today:/ {print $(NF-3)}' | sed 's/\.//'
>> 14582
>>
>> Can we only use AWK to change "14.582" to "14582"?

>
>awk -F"[<>]+" '/Uploads\ today/{ sub(/\./,""); print $(NF-3) }'
>
>or, if we're playing golf:
>
>awk '/Uploads\ today/ && gsub(/[^0-9]/,"")'

^^.
`--> is this required for gawk? What's the effect
if it is missing, 'cos gawk doesn't seem to mind here?

2. Nice eagle shot )

Grant.
--
http://bugsplatter.id.au/
Reply With Quote
  #6  
Old 09-11-2008, 10:34 PM
Ed Morton
Guest
 
Default Re: Parse and Replace

On 9/11/2008 6:14 PM, Grant wrote:
> On Thu, 11 Sep 2008 14:12:20 -0500, Ed Morton <morton@lsupcaemnt.com> wrote:
>
>
>>
>>On 8/14/2008 5:15 PM, dnlchen@gmail.com wrote:
>>
>>>Input:
>>>
>>>Uploads today: <span style="font-weight:bold;">14.582</span></div>
>>>
>>>Output: 14582
>>>
>>># awk -F"[<>]+" '/Uploads\ today:/ {print $(NF-3)}' | sed 's/\.//'
>>>14582
>>>
>>>Can we only use AWK to change "14.582" to "14582"?

>>
>>awk -F"[<>]+" '/Uploads\ today/{ sub(/\./,""); print $(NF-3) }'
>>
>>or, if we're playing golf:
>>
>>awk '/Uploads\ today/ && gsub(/[^0-9]/,"")'

>
> ^^.
> `--> is this required for gawk? What's the effect
> if it is missing, 'cos gawk doesn't seem to mind here?


No, I just copied-pasted from the original without thinking about it. It's not
doing anything useful.

Ed.

>
> 2. Nice eagle shot )
>
> Grant.


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:09 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.