I guess this has been posted hundred times, but my search string show
me trheads i don't understand.
need to extract the fields after a match, could be any position,
discard future equal string.
let me explain.
infile.txt
str1 str2 str3 str4 err003 str5 str...N
str1 str2 str3 str4 str5 err002 str5 str...N
str1 str2 err003 str3 str...N
str1 str2 str3 err002 str4 str...N
so I must search /err[1-9]/ and grab the subsequents fields. but if
I find the same err# discard it.
the desire output will be.
err002 str# str#+1 they are erros so is the same text after
err003 str# str#+1
once Ed show me
awk 'c&&c--;/pattern/{c=N}' file but I did not understand, I did'nt
want to bother him , to wait to reach the desire level on awk, haven't
get there , but need to do this..
Thanks.
|
|
0
|
|
|
|
Reply
|
lxvasquez (45)
|
11/12/2007 4:42:51 PM |
|
On 11/12/2007 10:42 AM, Atropo wrote:
> I guess this has been posted hundred times, but my search string show
> me trheads i don't understand.
>
> need to extract the fields after a match, could be any position,
> discard future equal string.
>
> let me explain.
>
> infile.txt
> str1 str2 str3 str4 err003 str5 str...N
> str1 str2 str3 str4 str5 err002 str5 str...N
> str1 str2 err003 str3 str...N
> str1 str2 str3 err002 str4 str...N
>
> so I must search /err[1-9]/ and grab the subsequents fields. but if
> I find the same err# discard it.
discard the first occurence you found, or ignore subsequent occurences you find?
> the desire output will be.
>
> err002 str# str#+1 they are erros so is the same text after
> err003 str# str#+1
>
that would've been much more useful if you'd shown the desired output given the
input you posted.
> once Ed show me
>
> awk 'c&&c--;/pattern/{c=N}' file but I did not understand, I did'nt
> want to bother him , to wait to reach the desire level on awk, haven't
> get there , but need to do this..
That's the solution to a totally different problem.
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
11/12/2007 11:34:30 PM
|
|
On 12 nov, 18:34, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 11/12/2007 10:42 AM, Atropo wrote:
>
>
>
> > I guess this has been posted hundred times, but my search string show
> > me trheads i don't understand.
>
> > need to extract the fields after a match, could be any position,
> > discard future equal string.
>
> > let me explain.
>
> > infile.txt
> > str1 str2 str3 str4 err003 str5 str...N
> > str1 str2 str3 str4 str5 err002 str5 str...N
> > str1 str2 err003 str3 str...N
> > str1 str2 str3 err002 str4 str...N
>
> > so I must search /err[1-9]/ and grab the subsequents fields. but if
> > I find the same err# discard it.
>
> discard the first occurence you found, or ignore subsequent occurences you find?
>
> > the desire output will be.
>
> > err002 str# str#+1 they are erros so is the same text after
> > err003 str# str#+1
>
> that would've been much more useful if you'd shown the desired output given the
> input you posted.
>
> > once Ed show me
>
> > awk 'c&&c--;/pattern/{c=N}' file but I did not understand, I did'nt
> > want to bother him , to wait to reach the desire level on awk, haven't
> > get there , but need to do this..
>
> That's the solution to a totally different problem.
>
> Ed.
Sorry Ed for not being clear.
having a file like the infile above, I want to search for a pattern
"err" that could be on any position, take all the fields after this
field, including it. and as you said ignore subsequent occurences of
the patterm i've found.
The desired output will be.
err003 str5 str...N I mean the field that match and all
subsequents fields
err002 str5 str...N
again sorry for including the hint you gave me before, I get lost
trying to figure out an approach.
PD. one last tihng , how do I trim the pattern from the field.? I
mean the field is "err003" I look for the pattern "err" but what I
want is "003" for the output
|
|
0
|
|
|
|
Reply
|
Atropo
|
11/13/2007 4:35:08 AM
|
|
Atropo wrote:
> On 12 nov, 18:34, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>>On 11/12/2007 10:42 AM, Atropo wrote:
>>
>>
>>
>>
>>>I guess this has been posted hundred times, but my search string show
>>>me trheads i don't understand.
>>
>>>need to extract the fields after a match, could be any position,
>>>discard future equal string.
>>
>>>let me explain.
>>
>>>infile.txt
>>>str1 str2 str3 str4 err003 str5 str...N
>>>str1 str2 str3 str4 str5 err002 str5 str...N
>>>str1 str2 err003 str3 str...N
>>>str1 str2 str3 err002 str4 str...N
>>
>>>so I must search /err[1-9]/ and grab the subsequents fields. but if
>>>I find the same err# discard it.
>>
>>discard the first occurence you found, or ignore subsequent occurences you find?
>>
>>
>>>the desire output will be.
>>
>>>err002 str# str#+1 they are erros so is the same text after
>>>err003 str# str#+1
>>
>>that would've been much more useful if you'd shown the desired output given the
>>input you posted.
>>
>>
>>>once Ed show me
>>
>>>awk 'c&&c--;/pattern/{c=N}' file but I did not understand, I did'nt
>>>want to bother him , to wait to reach the desire level on awk, haven't
>>>get there , but need to do this..
>>
>>That's the solution to a totally different problem.
>>
>> Ed.
>
>
> Sorry Ed for not being clear.
>
> having a file like the infile above, I want to search for a pattern
> "err" that could be on any position, take all the fields after this
> field, including it. and as you said ignore subsequent occurences of
> the patterm i've found.
>
> The desired output will be.
> err003 str5 str...N I mean the field that match and all
> subsequents fields
> err002 str5 str...N
>
> again sorry for including the hint you gave me before, I get lost
> trying to figure out an approach.
>
> PD. one last tihng , how do I trim the pattern from the field.? I
> mean the field is "err003" I look for the pattern "err" but what I
> want is "003" for the output
>
awk '
match($0,/err[0-9]+/) { e=substr($0,RSTART,RLENGTH) }
!(e in err) { err[e]; print substr($0,RSTART+3) }
'
Janis
|
|
0
|
|
|
|
Reply
|
Janis
|
11/13/2007 4:58:35 AM
|
|
On 12 nov, 23:58, Janis Papanagnou <Janis_Papanag...@hotmail.com>
wrote:
> Atropo wrote:
> > On 12 nov, 18:34, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
> >>On 11/12/2007 10:42 AM, Atropo wrote:
>
> >>>I guess this has been posted hundred times, but my search string show
> >>>me trheads i don't understand.
>
> >>>need to extract the fields after a match, could be any position,
> >>>discard future equal string.
>
> >>>let me explain.
>
> >>>infile.txt
> >>>str1 str2 str3 str4 err003 str5 str...N
> >>>str1 str2 str3 str4 str5 err002 str5 str...N
> >>>str1 str2 err003 str3 str...N
> >>>str1 str2 str3 err002 str4 str...N
>
> >>>so I must search /err[1-9]/ and grab the subsequents fields. but if
> >>>I find the same err# discard it.
>
> >>discard the first occurence you found, or ignore subsequent occurences you find?
>
> >>>the desire output will be.
>
> >>>err002 str# str#+1 they are erros so is the same text after
> >>>err003 str# str#+1
>
> >>that would've been much more useful if you'd shown the desired output given the
> >>input you posted.
>
> >>>once Ed show me
>
> >>>awk 'c&&c--;/pattern/{c=N}' file but I did not understand, I did'nt
> >>>want to bother him , to wait to reach the desire level on awk, haven't
> >>>get there , but need to do this..
>
> >>That's the solution to a totally different problem.
>
> >> Ed.
>
> > Sorry Ed for not being clear.
>
> > having a file like the infile above, I want to search for a pattern
> > "err" that could be on any position, take all the fields after this
> > field, including it. and as you said ignore subsequent occurences of
> > the patterm i've found.
>
> > The desired output will be.
> > err003 str5 str...N I mean the field that match and all
> > subsequents fields
> > err002 str5 str...N
>
> > again sorry for including the hint you gave me before, I get lost
> > trying to figure out an approach.
>
> > PD. one last tihng , how do I trim the pattern from the field.? I
> > mean the field is "err003" I look for the pattern "err" but what I
> > want is "003" for the output
>
> awk '
> match($0,/err[0-9]+/) { e=substr($0,RSTART,RLENGTH) }
> !(e in err) { err[e]; print substr($0,RSTART+3) }
> '
>
> Janis- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -
Excellent Janis, it runs like a charm. thanks to Ed too.
|
|
0
|
|
|
|
Reply
|
Atropo
|
11/13/2007 11:37:44 AM
|
|
|
4 Replies
178 Views
(page loaded in 0.09 seconds)
|