Solved

Using exact matching with grep in Shell program

Posted on 2006-10-19
2
1,110 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

690 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