PHIL Sawyer
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
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
perl -ne 'BEGIN{$t=shift}$c=$_ if/create\s+file/; /\b$t\b/&&print $c,$t,"\n"' mytable3 < sampletext
ASKER
Sorry - should have said I'm using Ruby. Will this still work?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks