linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* extract the data from buffer
@ 2009-01-16 15:54 Jai Sharma
  2009-01-16 16:55 ` Jesse Ruffin
  2009-01-16 17:47 ` ben
  0 siblings, 2 replies; 4+ messages in thread
From: Jai Sharma @ 2009-01-16 15:54 UTC (permalink / raw)
  To: linux-c-programming

Hi

I want to extract variables values from a string buffer. Can anyone
pleease tell me how can i do that.
In C how to use perl like regular expressions.


Channel              Location             State   Application(Data)
SIP/5078-099b4b48    s@newvcci:1          Ringing AppQueue((Outgoing Line))
SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
SIP/5080-09964168    s@newvcci:1          Up      Bridged Call(SIP/66.119.60.21-
SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
SIP/5079-09924998    s@newvcci:1          Up      Bridged Call(SIP/66.119.60.21-
SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
SIP/5041-0993ee38    s@newvcci:1          Up      Bridged Call(SIP/66.119.60.21-
SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
SIP/5010-098e7760    tsihomephoneservice@ Up      Bridged Call(SIP/63.111.11.135
SIP/63.111.11.135-09 tsihomephoneservice@ Up      Queue(tsihomephoneservice||||9
10 active channels
5 of 200 max active calls ( 2.50% of capacity)


I want to extract three numeric data fields from last line:
as

%d of %d max active calls ( %l% of capacity)
result : 5,200,2.50

means 2.5


Thanks and Regards

Jai

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: extract the data from buffer
  2009-01-16 15:54 extract the data from buffer Jai Sharma
@ 2009-01-16 16:55 ` Jesse Ruffin
  2009-01-16 17:31   ` ben
  2009-01-16 17:47 ` ben
  1 sibling, 1 reply; 4+ messages in thread
From: Jesse Ruffin @ 2009-01-16 16:55 UTC (permalink / raw)
  To: linux-c-programming

If you really want to use Perl style regular expressions, use libpcre (www.pcre.org). It will be available in your package manager, and probably already installed. If you don't need the full functionality of a regex, look into the scanf family of functions.

Jesse Ruffin

On Friday 16 January 2009 10:54:11 Jai Sharma wrote:
> Hi
> 
> I want to extract variables values from a string buffer. Can anyone
> pleease tell me how can i do that.
> In C how to use perl like regular expressions.
> 
> 
> Channel              Location             State   Application(Data)
> SIP/5078-099b4b48    s@newvcci:1          Ringing AppQueue((Outgoing Line))
> SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
> SIP/5080-09964168    s@newvcci:1          Up      Bridged Call(SIP/66.119.60.21-
> SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
> SIP/5079-09924998    s@newvcci:1          Up      Bridged Call(SIP/66.119.60.21-
> SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
> SIP/5041-0993ee38    s@newvcci:1          Up      Bridged Call(SIP/66.119.60.21-
> SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
> SIP/5010-098e7760    tsihomephoneservice@ Up      Bridged Call(SIP/63.111.11.135
> SIP/63.111.11.135-09 tsihomephoneservice@ Up      Queue(tsihomephoneservice||||9
> 10 active channels
> 5 of 200 max active calls ( 2.50% of capacity)
> 
> 
> I want to extract three numeric data fields from last line:
> as
> 
> %d of %d max active calls ( %l% of capacity)
> result : 5,200,2.50
> 
> means 2.5
> 
> 
> Thanks and Regards
> 
> Jai

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: extract the data from buffer
  2009-01-16 16:55 ` Jesse Ruffin
@ 2009-01-16 17:31   ` ben
  0 siblings, 0 replies; 4+ messages in thread
From: ben @ 2009-01-16 17:31 UTC (permalink / raw)
  To: linux-c-programming

there are also POSIX regular expressions, bundled with the libc.
$ man regcomp or man regex (same)
this is highly portable, and already in libc. those RE are the same as 
sed's expressions (except shell escapes are not needed).

Jesse Ruffin a écrit :
> If you really want to use Perl style regular expressions, use libpcre (www.pcre.org). It will be available in your package manager, and probably already installed. If you don't need the full functionality of a regex, look into the scanf family of functions.
> 
> Jesse Ruffin
> 
> On Friday 16 January 2009 10:54:11 Jai Sharma wrote:
>> Hi
>>
>> I want to extract variables values from a string buffer. Can anyone
>> pleease tell me how can i do that.
>> In C how to use perl like regular expressions.
>>
>>
>> Channel              Location             State   Application(Data)
>> SIP/5078-099b4b48    s@newvcci:1          Ringing AppQueue((Outgoing Line))
>> SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
>> SIP/5080-09964168    s@newvcci:1          Up      Bridged Call(SIP/66.119.60.21-
>> SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
>> SIP/5079-09924998    s@newvcci:1          Up      Bridged Call(SIP/66.119.60.21-
>> SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
>> SIP/5041-0993ee38    s@newvcci:1          Up      Bridged Call(SIP/66.119.60.21-
>> SIP/66.119.60.21-099 s@tracphone:6        Up      Queue(tracphone||||3600)
>> SIP/5010-098e7760    tsihomephoneservice@ Up      Bridged Call(SIP/63.111.11.135
>> SIP/63.111.11.135-09 tsihomephoneservice@ Up      Queue(tsihomephoneservice||||9
>> 10 active channels
>> 5 of 200 max active calls ( 2.50% of capacity)
>>
>>
>> I want to extract three numeric data fields from last line:
>> as
>>
>> %d of %d max active calls ( %l% of capacity)
>> result : 5,200,2.50
>>
>> means 2.5
>>
>>
>> Thanks and Regards
>>
>> Jai
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: extract the data from buffer
  2009-01-16 15:54 extract the data from buffer Jai Sharma
  2009-01-16 16:55 ` Jesse Ruffin
@ 2009-01-16 17:47 ` ben
  1 sibling, 0 replies; 4+ messages in thread
From: ben @ 2009-01-16 17:47 UTC (permalink / raw)
  To: linux-c-programming


this /RE/ should match the desired 3 numbers (inside parenthesis):

/^([0-9]*) of ([0-9]*) max .* ([0-9]*\.*[0-9]*)% of.*/
- ben
Jai Sharma a écrit :
> Hi
> 
> I want to extract variables values from a string buffer. Can anyone
> pleease tell me how can i do that.
> In C how to use perl like regular expressions.
> 
> [...]
> SIP/63.111.11.135-09 tsihomephoneservice@ Up      Queue(tsihomephoneservice||||9
> 10 active channels
> 5 of 200 max active calls ( 2.50% of capacity)
> 
> 
> I want to extract three numeric data fields from last line:
> as
> 
> %d of %d max active calls ( %l% of capacity)
> result : 5,200,2.50
> 
> means 2.5
> 
> 
> Thanks and Regards
> 
> Jai
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-01-16 17:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-16 15:54 extract the data from buffer Jai Sharma
2009-01-16 16:55 ` Jesse Ruffin
2009-01-16 17:31   ` ben
2009-01-16 17:47 ` ben

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).