Afficher un message
Vieux 29/05/2007, 15h15   #8
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

On 28 maio, 18:37, Janis Papanagnou <Janis_Papanag...@hotmail.com>
wrote:
> apogeusiste...@gmail.com wrote:
> > On 28 maio, 12:34, Ed Morton <mor...@lsupcaemnt.com> wrote:

>
> >>Franco wrote:

>
> >>>On May 28, 2:52 pm, apogeusiste...@gmail.com wrote:

>
> >>>>Hi:
> >>>>I need search a specified string in a file, after the word
> >>>>"mounting" , like this:

>
> >>>>solaris> cat file
> >>>>netbackup, orac_ux001 backup, streaming yes, multiplexing ok ,
> >>>>mounting M00541 police enabled, data file

>
> >>>>Which awk command can I issue to extract only the "M00541" string
> >>>>inside a file ?

>
> >>>>Thanks

>
> >>>Why not use grep ?

>
> >>>grep -i mounting file ???????

>
> >>>This will extract all instances' of mounting and its associated line.

>
> >>He doesn't want the line or the word itself, he wants just the word
> >>following it the word he's searching for.

>
> >>For the OP - This will work for the sample input you posted:

>
> >>awk '{for (i=1;i<=NF;i++) if ($i == "mounting") print $(i+1)}' file

>
> >>but what would you want to have happen if "mounting" was the last word
> >>on a line?

>
> >> Ed.- Ocultar texto entre aspas -

>
> >>- Mostrar texto entre aspas -

>
> > Is there any way to limit the substring founded in 6 characters ?
> > I´m getting this:

>
> You wouldn't get that with your explanation and with the example data
> you gave above. To limit the string to six characters replace/extend
> the print command by
>
> print substr($(i+1),1,6)
>
> Janis
>
>
>
>
>
> > M00541,05/28/07

>
> > Thank you !- Ocultar texto entre aspas -

>
> - Mostrar texto entre aspas -- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -


Thank you and sorry for my wrong example !

  Réponse avec citation
 
Page generated in 0,35363 seconds with 9 queries