Link to home
Start Free TrialLog in
Avatar of PHIL Sawyer
PHIL SawyerFlag for United Kingdom of Great Britain and Northern Ireland

asked on

capturing text

Hi
I have a large txt file where I want to return lines between a given condition eg
sample text...
create file 1
select * from mytable1
where id = 1
create file 2
select * from mytable3
where id = 1
create file 3
select * from
    mytable3
where id = 1

.. I would like a regular expression where if I want to search for "mytable3" and what "creat file" name it is contained within.
So, for "mytable3" the returned data should read...
create file2
mytable3
create file3
mytable3

Help much appreciated
Avatar of ozo
ozo
Flag of United States of America image

perl -ne 'BEGIN{$t=shift}$c=$_ if/create\s+file/; /\b$t\b/&&print $c,$t,"\n"' mytable3 < sampletext
Avatar of PHIL Sawyer

ASKER

Sorry - should have said I'm using Ruby. Will this still work?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks