Solved

A grep question

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

785 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