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 > extract some lines from file
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

extract some lines from file

Réponse
 
LinkBack Outils de la discussion
Vieux 17/07/2007, 01h05   #1
rachit7@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut extract some lines from file

I am writing a ksh script and trying to extract some lines that come
after a particular line. Following is my sample file
================================================== =======================
Number of students in class are 50
Number of students with GPA>3.0 are 18
Some more lines

Last Name First Name
Class Date GPA
--------------------------------------------------------------------------------------------------------------------------------------
James Dave
xxxx xxxx xxxxxx
xxxxx xxxxx
xxxxx xxxxx xxxxxxxx
xxxxxxx xxxxxxxxxx
xxxxx xxxxxxxxxx xxxxxxxxxx

Professor: Dr. XYZ
School:XYZ
================================================== ==========================

I want all the lines that are below Last Name,First Name, Class,
Date,GPA heading but before Professorr. XYZ.

Any ?
Regards,

  Réponse avec citation
Vieux 17/07/2007, 01h50   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: extract some lines from file

rachit7@gmail.com wrote:
> I am writing a ksh script and trying to extract some lines that come
> after a particular line. Following is my sample file
> ================================================== =======================
> Number of students in class are 50
> Number of students with GPA>3.0 are 18
> Some more lines
>
> Last Name First Name
> Class Date GPA
> --------------------------------------------------------------------------------------------------------------------------------------
> James Dave
> xxxx xxxx xxxxxx
> xxxxx xxxxx
> xxxxx xxxxx xxxxxxxx
> xxxxxxx xxxxxxxxxx
> xxxxx xxxxxxxxxx xxxxxxxxxx
>
> Professor: Dr. XYZ
> School:XYZ
> ================================================== ==========================
>
> I want all the lines that are below Last Name,First Name, Class,
> Date,GPA heading but before Professorr. XYZ.


Assuming there are some line-breaks in the above posting that are
non-existent in your actual data.

You can take the dashes and the empty line as separator...

awk '/^------------------/,/^$/' your-data-file

If the assumption is not valid, come back and ask.

Janis

>
> Any ?
> Regards,
>

  Réponse avec citation
Vieux 17/07/2007, 12h12   #3
rachit7@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: extract some lines from file

On Jul 16, 8:50 pm, Janis Papanagnou <Janis_Papanag...@hotmail.com>
wrote:
> rach...@gmail.com wrote:
> > I am writing a ksh script and trying to extract some lines that come
> > after a particular line. Following is my sample file
> > ================================================== =======================
> > Number of students in class are 50
> > Number of students with GPA>3.0 are 18
> > Some more lines

>
> > Last Name First Name
> > Class Date GPA
> > --------------------------------------------------------------------------------------------------------------------------------------
> > James Dave
> > xxxx xxxx xxxxxx
> > xxxxx xxxxx
> > xxxxx xxxxx xxxxxxxx
> > xxxxxxx xxxxxxxxxx
> > xxxxx xxxxxxxxxx xxxxxxxxxx

>
> > Professor: Dr. XYZ
> > School:XYZ
> > ================================================== ==========================

>
> > I want all the lines that are below Last Name,First Name, Class,
> > Date,GPA heading but before Professorr. XYZ.

>
> Assuming there are some line-breaks in the above posting that are
> non-existent in your actual data.
>
> You can take the dashes and the empty line as separator...
>
> awk '/^------------------/,/^$/' your-data-file
>
> If the assumption is not valid, come back and ask.
>
> Janis
>
>
>
> > Any ?
> > Regards,


Thanks Janis
It works. I didn't know that one can give two line saprators in awk to
limit the contents of an input file. Thanks again.
I have one more question about system() function in awk but I will ask
it in a new post.

Regards,
Rachit.

  Réponse avec citation
Vieux 18/07/2007, 04h58   #4
mik3l3374@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: extract some lines from file

On Jul 17, 8:05 am, rach...@gmail.com wrote:
> I am writing a ksh script and trying to extract some lines that come
> after a particular line. Following is my sample file
> ================================================== =======================
> Number of students in class are 50
> Number of students with GPA>3.0 are 18
> Some more lines
>
> Last Name First Name
> Class Date GPA
> --------------------------------------------------------------------------------------------------------------------------------------
> James Dave
> xxxx xxxx xxxxxx
> xxxxx xxxxx
> xxxxx xxxxx xxxxxxxx
> xxxxxxx xxxxxxxxxx
> xxxxx xxxxxxxxxx xxxxxxxxxx
>
> Professor: Dr. XYZ
> School:XYZ
> ================================================== ==========================
>
> I want all the lines that are below Last Name,First Name, Class,
> Date,GPA heading but before Professorr. XYZ.
>
> Any ?
> Regards,


awk 'BEGIN{RS="";FS="[-]+"}{ print $2}' "file"

  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 22h19.


Édité par : vBulletin® version 3.7.2
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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11044 seconds with 12 queries