|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
List,
I want to print a section inside a text FILE between REGEX1 and REGEX2 without printing both REGEX1 and REGEX2. How do I do this? sed -n '/REGEX1/,/REGEX2/p' prints the section alongwith REGEX1 and REGEX2. Please . I apologise if this is a repost. I wan't fortunate enough to find it. Thanks Anirbid |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
* anirbid.banerjee@gmail.com [2007.05.04 08:22]:
> I want to print a section inside a text FILE between > REGEX1 and REGEX2 without printing both REGEX1 and REGEX2. > How do I do this? http://sed.sourceforge.net/sedfaq4.html#s4.24 -- JR |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
anirbid.banerjee@gmail.com wrote:
> List, > > I want to print a section inside a text FILE between REGEX1 and REGEX2 > without printing both REGEX1 and REGEX2. How do I do this? > > sed -n '/REGEX1/,/REGEX2/p' prints the section alongwith REGEX1 and > REGEX2. Please . > > I apologise if this is a repost. I wan't fortunate enough to find it. > > Thanks > Anirbid > Just use awk and you can trivially control whatever you want printed, e.g. this will do what you want: awk '/REGEX2/{found=0} found{print} /REGEX1/{found=1}' file just change where "found" is set/tested to control whether either of the matching regex lines are printed if you want to do something different in future. Ed. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Hello!
Maybe you try this with Sed: stephan@unimatrix ~ $ echo -e "re1\nfoo bar\nre2" | sed -n '/re1/,/re2/{ > /re1/d > /re2/d > /^$/d > p > } > ' foo bar |
|
![]() |
| Outils de la discussion | |
|
|