Solved

A grep question

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 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