Solved

A grep question

Posted on 2001-08-01
5
301 Views
Last Modified: 2010-04-21
I have a variable $MACHINE and I want to do an exact grep match for $MACHINE. How to do this when it's a variable?
0
Comment
Question by:CyberGod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
zmanz earned 50 total points
ID: 6341438
I don't fully understand what you want.
If you mean to match a string $MACHINE you can do \$MACHINE
If you mean something else you may have to do ${MACHINE}
Or if you mean something else you just use that variable for
pattern instead of a string literal.

grep \$MACHINE filetolookin <cr>
grep stuff${MACHINE}otherstuff filetolookin <cr>
grep $MACHINE filetolookin <cr>

 
Again, I'm not sure what you want. I'm just making guesses.

0
 

Author Comment

by:CyberGod
ID: 6341626
Here is an example of what my problem is:

I assign a value to my variable:
MACHINE=192.168.0.10

When I do this:
cat /etc/hosts | grep $MACHINE
it gives me every host that have .10* like
192.168.0.10
192.168.0.101
192.168.0.105 etc.
I want to match exactly the value that I've assigned.
0
 

Author Comment

by:CyberGod
ID: 6341631
Here is an example of what my problem is:

I assign a value to my variable:
MACHINE=192.168.0.10

When I do this:
cat /etc/hosts | grep $MACHINE
it gives me every host that have .10* like
192.168.0.10
192.168.0.101
192.168.0.105 etc.
I want to match exactly the value that I've assigned.
0
 

Author Comment

by:CyberGod
ID: 6341704
Here is an example of what my problem is:

I assign a value to my variable:
MACHINE=192.168.0.10

When I do this:
cat /etc/hosts | grep $MACHINE
it gives me every host that have .10* like
192.168.0.10
192.168.0.101
192.168.0.105 etc.
I want to match exactly the value that I've assigned.
0
 
LVL 1

Expert Comment

by:zmanz
ID: 6341808
Try:
 cat /etc/hosts | grep "${MACHINE}[^0-9]"
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question