Solved

Using exact matching with grep in Shell program

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

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…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

21 Experts available now in Live!

Get 1:1 Help Now