Solved

Using exact matching with grep in Shell program

Posted on 2006-10-19
2
1,108 Views
Last Modified: 2008-03-10
I writing a shell script, and in the script I would like to grep to perform an exact string match in another file.  Whenever I try to do this, the variable that I save the grep return in does not give the right results when checking that value.  Can someone please tell me if I am missing something.  Below is the portion of the code that I am working with.

serial="test1"
output=./script_report

check=`grep -m 1 -w "$serial" $output`

if [ "$check" != "" ]
then
........

When this function is run and "test1" does not exist within the file but a the string "test" does exist, the conditional returns true.  (should return false)

Thanks for the help.
0
Comment
Question by:sctccomm
[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
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 17770218
It is returning false when I try it
0
 

Author Comment

by:sctccomm
ID: 17770616
Okay, I fixed the problem, the grep work fine the way it is.  Just forgot to update the value of check after the first time.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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