|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 ! |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 ! > |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 ! |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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 ? |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|