Results 1 to 4 of 4
if I'd a file like this
something
somethine123
begin something end
begin xyz end
somethingelse
and I want to find the strings only between begin and end, exluding begin and ...
- 12-15-2010 #1Just Joined!
- Join Date
- Aug 2005
- Posts
- 2
grep ??
if I'd a file like this
something
somethine123
begin something end
begin xyz end
somethingelse
and I want to find the strings only between begin and end, exluding begin and end;
How can I grep that?
- 12-15-2010 #2
I'm no expert at regular expressions, but you could try an Online Regular Expression Builder, such as this one. This can help you understand regex much better. You can feed these into grep as the search sequence.
Linux user #126863 - see http://linuxcounter.net/
- 12-15-2010 #3
Use lookahead and lookbehind expressions:
Code:grep -oP '(?<=begin ).+?(?= end)' file
Refining Linux Advent calendar: “24 Outstanding ZSH Gems”
- 12-16-2010 #4Just Joined!
- Join Date
- Aug 2005
- Posts
- 2
Thanks Manko10, It worked for me.
& Thanks Roxoff, that was really helpful in knowing the regs


Reply With Quote