List Info

Thread: One Regex match per file




One Regex match per file
country flaguser name
United States
2007-02-28 02:09:47
Hello all,

I'm trying to figure out a way to write a Regex statement
(for each
file) where it stops after the first occurrence is
found/matched.

I have tons of files having multiple words having a specific
word
pattern.  I need to just locate the first position of that
pattern in
each file before regex stops searching for THAT file and
moves on to
the next file.

Any ideas?

Thanks,
Todd


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: One Regex match per file
country flaguser name
United States
2007-02-28 09:56:50
On Feb 28, 3:09 am, "Todd Hlavacek"
<handsha...gmail.com> wrote:
> Hello all,
>
> I'm trying to figure out a way to write a Regex
statement (for each
> file) where it stops after the first occurrence is
found/matched.
>
> I have tons of files having multiple words having a
specific word
> pattern.  I need to just locate the first position of
that pattern in
> each file before regex stops searching for THAT file
and moves on to
> the next file.

Hi, Todd:

you need to tell us which tool you want to use to handle
your problem.
>From my experience, GNU 'awk' has the easiest way:

awk '/pattern/{print FILENAME, FNR; nextfile}' file*

This prints the filename followed by the line_number of the
first
match..

Regards,
Xicheng


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: One Regex match per file
country flaguser name
United States
2007-02-28 10:24:44
On Feb 28, 10:56 am, "Xicheng Jia" <xich...gmail.com> wrote:
> On Feb 28, 3:09 am, "Todd Hlavacek"
<handsha...gmail.com> wrote:
>
> > Hello all,
>
> > I'm trying to figure out a way to write a Regex
statement (for each
> > file) where it stops after the first occurrence is
found/matched.
>
> > I have tons of files having multiple words having
a specific word
> > pattern.  I need to just locate the first position
of that pattern in
> > each file before regex stops searching for THAT
file and moves on to
> > the next file.
>
> Hi, Todd:
>
> you need to tell us which tool you want to use to
handle your problem.
>
> >From my experience, GNU 'awk' has the easiest way:
>
> awk '/pattern/{print FILENAME, FNR; nextfile}' file*
>
> This prints the filename followed by the line_number of
the first
> match..

Another way with Perl:

  perl -lne 'print "$ARGV $." and close ARGV
if/pattern/' file*

Regards,
Xicheng


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )