PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > sed Printing between Regular Expressions
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

sed Printing between Regular Expressions

Réponse
 
LinkBack Outils de la discussion
Vieux 04/05/2007, 10h22   #1
anirbid.banerjee@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sed Printing between Regular Expressions

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

  Réponse avec citation
Vieux 04/05/2007, 15h49   #2
Jean-Rene David
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed Printing between Regular Expressions

* 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
  Réponse avec citation
Vieux 04/05/2007, 16h02   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed Printing between Regular Expressions

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.
  Réponse avec citation
Vieux 04/05/2007, 17h07   #4
Stephan Grein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed Printing between Regular Expressions

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h48.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08436 seconds with 12 queries