1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

o/t need script help with grep

Discussion in 'Tomato Firmware' started by yaqui, Jul 28, 2007.

  1. yaqui

    yaqui LI Guru Member

    Is there any way to grep a string contained in a variable?

    stringinthisvariable=some words

    grep $stringinthisvariable /etc/file

    Doesn't seem to work, is there any way?
  2. mikester

    mikester Network Guru Member

    Are you trying to parse data in a variable?

    i.e. $PATH=/bin:/usr/bin:/sbin:/usr/sbin:/home/root:

    to find the word "bin" in your $PATH use the command

    echo $PATH | grep bin

    or find a file name containing "bin" in /etc?

    find /etc * | grep bin

    you might want to look up I/O redirection or "pipe" or "pipelines" and linux
  3. yaqui

    yaqui LI Guru Member

    NO... I am looking for the string "some words" in the file-> /etc/file

    I want "some words" to be a variable.
  4. mstombs

    mstombs Network Guru Member

    ? grep returns lines containing the search string i.e.

    # echo "this line contains some words" >tmp.tmp
    # grep "some words" tmp.tmp
    this line contains some words
    # str='some words'
    # grep "$str" tmp.tmp
    this line contains some words
  5. azeari

    azeari LI Guru Member

    cat file | grep $variable ?
  6. yaqui

    yaqui LI Guru Member

    Yes that is what I wanted to do, for some reason it didn't work when I tried.

    I try again, thanks

Share This Page