Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

A grep question

Posted on 2001-08-01
5
Medium Priority
?
305 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
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
zmanz earned 100 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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 Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

971 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