INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

grep exact pattern

grep exact pattern

(OP)
Hi
I am using grep to extract a certain pattern in the example files below. How do I extract pattern 'T1' and not 'T123'?

CODE

cat pattern
id
T1
T23
T55

CODE

cat file
id    name    length
T5    Lypla1    2433
T55    sea3    2668
T123    Tmea1    2671
T23    nrea1    2564
T1    mea1    250
T10    mrty1    22

CODE

grep -f pattern file
id    name    length
T55    sea3    2668
T123    Tmea1    2671
T23    nrea1    2564
T1    mea1    250
T10    mrty1    22

the output should be:

CODE

id    name    length
T1    mea1    250
T23    nrea1    2564
T55    sea3    2668
Thank you for your help
Joseph

 

RE: grep exact pattern

Or adapt your regular expression to what you really want:

CODE

cat pattern
id
T1[^[:digit:]]
T23
T55

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close