Advertisement

12.14.2007 at 09:29PM PST, ID: 23025156
[x]
Attachment Details

Extracting certain numbers from text file

Asked by singhch in Regular Expressions, CYGWIN

Tags: , , , ,

Hi there,

How can I specify in my regex (I am using grep in Cygwin, perl regex with -P) to look for a particular text in a line and to carry on extracting all the lines until it finds another text that i am interested in.

for example, the following is the text file

line 1 there is error
there are some info
this info is not important
error count is 42
line 2 there is no error
there are some info
line 3 there is error
there are some info
this info is not important
error count is 35

so basically, what I want from this text file is
line 1 = 42
line 3 = 35

i need to know the error count if there are any for the line no.
for starters, I have this regex  grep -i -P 'is error/r$'  mytext.txt (to get the line with eror)

but do i specify to grep that keep selecting the lines until you find a line that ends with digits [0-9]*$?

thanks

Start Free Trial
[+][-]12.14.2007 at 09:48PM PST, ID: 20476313

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.16.2007 at 02:55PM PST, ID: 20481970

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.18.2007 at 03:30PM PST, ID: 20496517

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.16.2008 at 08:34AM PST, ID: 20673345

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Regular Expressions, CYGWIN
Tags: numbers, extracting, file, from, text
Sign Up Now!
Solution Provided By: tdiops
Participating Experts: 3
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628