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

Finding a string in a file

Réponse
 
LinkBack Outils de la discussion
Vieux 28/05/2007, 14h52   #1
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Finding a string in a file

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

  Réponse avec citation
Vieux 28/05/2007, 16h18   #2
Franco
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

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.

  Réponse avec citation
Vieux 28/05/2007, 16h34   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

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.
  Réponse avec citation
Vieux 28/05/2007, 18h31   #4
tmp123
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

On May 28, 3: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


Could this statement be useful?

expr "`grep mounting file`" : 'mounting *\(\w*\)'

Kind regards.


  Réponse avec citation
Vieux 28/05/2007, 21h57   #5
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

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:

M00541,05/28/07

Thank you !

  Réponse avec citation
Vieux 28/05/2007, 22h34   #6
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

On 28 May 2007 13:57:44 -0700, apogeusistemas@gmail.com
<apogeusistemas@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?
>>

>
> Is there any way to limit the substring founded in 6 characters ?
> I´m getting this:
>
> M00541,05/28/07
>
> Thank you !
>

print substr($(i+1),1,6)
sub(/,.*/,"",$(i+1)); print $(i+1)

--
Recent investments will yield a slight profit.
  Réponse avec citation
Vieux 28/05/2007, 22h37   #7
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

apogeusistemas@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 !
>

  Réponse avec citation
Vieux 29/05/2007, 14h15   #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
Vieux 29/05/2007, 15h31   #9
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

apogeusistemas@gmail.com wrote:
> 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 ?

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

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

>>

<snip>
>> print substr($(i+1),1,6)

<snip>
> Thank you and sorry for my wrong example !
>


If you posted an accurate example, I suspect there's an even simpler
solution.

Ed.
  Réponse avec citation
Vieux 29/05/2007, 20h42   #10
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

On 29 maio, 11:31, Ed Morton <mor...@lsupcaemnt.com> wrote:
> apogeusiste...@gmail.com wrote:
> > 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 ?

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

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

>
> <snip>
> >> print substr($(i+1),1,6)

> <snip>
> > Thank you and sorry for my wrong example !

>
> If you posted an accurate example, I suspect there's an even simpler
> solution.
>
> Ed.- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -


How could I substitute string "mounting" for "media id" in this
script ?

  Réponse avec citation
Vieux 29/05/2007, 20h45   #11
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

apogeusistemas@gmail.com wrote:
> On 29 maio, 11:31, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>>apogeusiste...@gmail.com wrote:
>>
>>>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 ?

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

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

>>
>><snip>
>>
>>>> print substr($(i+1),1,6)

>>
>><snip>
>>
>>>Thank you and sorry for my wrong example !

>>
>>If you posted an accurate example, I suspect there's an even simpler
>>solution.
>>
>> Ed.- Ocultar texto entre aspas -
>>
>>- Mostrar texto entre aspas -

>
>
> How could I substitute string "mounting" for "media id" in this
> script ?
>


Post some real sample input and expected output or we can't give you
anything better than a guess.

Ed.
  Réponse avec citation
Vieux 29/05/2007, 20h51   #12
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

On 29 maio, 16:45, Ed Morton <mor...@lsupcaemnt.com> wrote:
> apogeusiste...@gmail.com wrote:
> > On 29 maio, 11:31, Ed Morton <mor...@lsupcaemnt.com> wrote:

>
> >>apogeusiste...@gmail.com wrote:

>
> >>>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 ?

>
> >><snip>

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

>
> >><snip>

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

>
> >><snip>

>
> >>>> print substr($(i+1),1,6)

>
> >><snip>

>
> >>>Thank you and sorry for my wrong example !

>
> >>If you posted an accurate example, I suspect there's an even simpler
> >>solution.

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

>
> >>- Mostrar texto entre aspas -

>
> > How could I substitute string "mounting" for "media id" in this
> > script ?

>
> Post some real sample input and expected output or we can't give you
> anything better than a guess.
>
> Ed.- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -



I need find DAY128 string after "media id" string:
solaris> cat file

TIME SERVER/CLIENT TEXT
05/29/2007 15:18:35 smmtzsux001-bkp smmtzslx002 client smmtzslx002
handling
path /full_CORP_on_4fiiupcc
05/29/2007 15:18:35 smmtzsux001-bkp smmtzslx002 starting backup job
(jobid=207,827)
05/29/2007 15:18:43 smmtzsux001-bkp smmtzslx002 begin writing backup
id
smmtzslx002_1180441115, copy 1, fragment 1, to
media id
DAY128 on drive index 5

  Réponse avec citation
Vieux 29/05/2007, 21h07   #13
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

apogeusistemas@gmail.com wrote:

<snip>
> I need find DAY128 string after "media id" string:
> solaris> cat file
>
> TIME SERVER/CLIENT TEXT
> 05/29/2007 15:18:35 smmtzsux001-bkp smmtzslx002 client smmtzslx002
> handling
> path /full_CORP_on_4fiiupcc
> 05/29/2007 15:18:35 smmtzsux001-bkp smmtzslx002 starting backup job
> (jobid=207,827)
> 05/29/2007 15:18:43 smmtzsux001-bkp smmtzslx002 begin writing backup
> id
> smmtzslx002_1180441115, copy 1, fragment 1, to
> media id
> DAY128 on drive index 5
>


Is your input file really split such that "media id" occurs on it's own
on the line after "to" and before the line that starts with "DAY128"?
The solutions will be pretty different based on whether or not what
we're seeing is caused by line-wrapping of your posting.

Ed.
  Réponse avec citation
Vieux 29/05/2007, 21h18   #14
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

On 29 maio, 17:07, Ed Morton <mor...@lsupcaemnt.com> wrote:
> apogeusiste...@gmail.com wrote:
>
> <snip>
>
> > I need find DAY128 string after "media id" string:
> > solaris> cat file

>
> > TIME SERVER/CLIENT TEXT
> > 05/29/2007 15:18:35 smmtzsux001-bkp smmtzslx002 client smmtzslx002
> > handling
> > path /full_CORP_on_4fiiupcc
> > 05/29/2007 15:18:35 smmtzsux001-bkp smmtzslx002 starting backup job
> > (jobid=207,827)
> > 05/29/2007 15:18:43 smmtzsux001-bkp smmtzslx002 begin writing backup
> > id
> > smmtzslx002_1180441115, copy 1, fragment 1, to
> > media id
> > DAY128 on drive index 5

>
> Is your input file really split such that "media id" occurs on it's own
> on the line after "to" and before the line that starts with "DAY128"?
> The solutions will be pretty different based on whether or not what
> we're seeing is caused by line-wrapping of your posting.
>
> Ed.


to media id DAY128 on drive index 5

  Réponse avec citation
Vieux 29/05/2007, 21h46   #15
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding a string in a file

apogeusistemas@gmail.com wrote:
> On 29 maio, 17:07, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>>apogeusiste...@gmail.com wrote:
>>
>><snip>
>>
>>>I need find DAY128 string after "media id" string:
>>>solaris> cat file

>>
>>> TIME SERVER/CLIENT TEXT
>>>05/29/2007 15:18:35 smmtzsux001-bkp smmtzslx002 client smmtzslx002
>>>handling
>>> path /full_CORP_on_4fiiupcc
>>>05/29/2007 15:18:35 smmtzsux001-bkp smmtzslx002 starting backup job
>>> (jobid=207,827)
>>>05/29/2007 15:18:43 smmtzsux001-bkp smmtzslx002 begin writing backup
>>>id
>>> smmtzslx002_1180441115, copy 1, fragment 1, to
>>>media id
>>> DAY128 on drive index 5

>>
>>Is your input file really split such that "media id" occurs on it's own
>>on the line after "to" and before the line that starts with "DAY128"?
>>The solutions will be pretty different based on whether or not what
>>we're seeing is caused by line-wrapping of your posting.
>>
>> Ed.

>
>
> to media id DAY128 on drive index 5
>


awk 'sub(/.*media id /,""){print $1}' file

Ed.
  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 22h13.


É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,38222 seconds with 23 queries