USER: mylogin NUM: 1
USER:my NUM:2
USER: other NUM: 3
I'm writing a script that will allow people to edit the NUM field. But
if their login is part of another person's login name then grep will
give me 2 lines (do a grep for "my" and you'll get 2 lines). To further
complicate the problem, there might be a space between USER: and the
login or there might not. Also sometimes there's a tab between the
login name and NUM: and sometimes it's spaces (I found this out when I
tried to do 'grep "my " tempfile' and it wouldn't work).
Any ideas are greatly appreciated.
shawn
Sent via Deja.com http://www.deja.com/
Before you buy.
This seems to work:
tab=`printf "\t"`;egrep "USER:[ $tab]+my[ $tab]+" test.dat
HTH...
In article <8vbv90$s0j$1...@nnrp1.deja.com>,
So change the first + to an asterisk (*)...
> Hi,
> How can I search for a specific name in a file? Here's how the file
> looks:
>
> USER: mylogin NUM: 1
> USER:my NUM:2
> USER: other NUM: 3
>
> I'm writing a script that will allow people to edit the NUM field. But
> if their login is part of another person's login name then grep will
> give me 2 lines (do a grep for "my" and you'll get 2 lines). To further
> complicate the problem, there might be a space between USER: and the
> login or there might not. Also sometimes there's a tab between the
> login name and NUM: and sometimes it's spaces (I found this out when I
> tried to do 'grep "my " tempfile' and it wouldn't work).
>
Hi Shawn,
try
rgrep "USER:.*my[\t\ ]+" <filename>
You can search for a particular group by using \(.*\) instead of ``my''
and
then recall the match with \1.
Hope this works for you.
Best,
Mike
try this: grep 'USER:.*my ' filename
In article <8vc1hn$u5b$1...@nnrp1.deja.com>,
holm...@my-deja.com wrote:
> That works as long as there is a space between USER: and the login. It
> won't work on the 2nd line in my example. We're getting closer!
>
> In article <8vbv90$s0j$1...@nnrp1.deja.com>,
> Glenn West <wes...@my-deja.com> wrote:
> > In article <8vbt3i$q65$1...@nnrp1.deja.com>,
> > holm...@my-deja.com wrote:
> > > Hi,
> > > How can I search for a specific name in a file? Here's how the
file
> > > looks:
> > >
> > > USER: mylogin NUM: 1
> > > USER:my NUM:2
> > > USER: other NUM: 3
> > >
> > > I'm writing a script that will allow people to edit the NUM field.
> But
> > > if their login is part of another person's login name then grep
will
> > > give me 2 lines (do a grep for "my" and you'll get 2 lines). To
> > further
> > > complicate the problem, there might be a space between USER: and
the
> > > login or there might not. Also sometimes there's a tab between the
> > > login name and NUM: and sometimes it's spaces (I found this out
> when I
> > > tried to do 'grep "my " tempfile' and it wouldn't work).
> > >
missed that, try this: egrep '.*USER:[ ]?my[\t]?' filename
In article <8vc431$pv$1...@nnrp1.deja.com>,
Or you can use
grep -w my <file>
Try narrowing grep's search by forcing the pattern to match entire
words:
$ grep -w my file
Would only match 'my'.
thks.jeff