Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003
    Posts
    106

    Unanswered: how to use grep to search within a string

    Hi,

    assume the shell script

    a="he is fine , thank you"

    i need to search for the word "fine" in this string.

    How can I do that.

    grep -w "fine"

    how to pass the variable $a to this grep statement.
    Sachi

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    You can do :

    echo $a | grep -w "fine"

    If you want to store the result in a variable :

    res=`echo $a | grep -w "fine"`
    Jean-Pierre.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •