Solved

A grep question

Posted on 2001-08-01
5
296 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 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now