grep dialog box

Discussion in 'Command Line' started by gordonnmurray, Apr 9, 2013.

  1. gordonnmurray

    gordonnmurray New Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hi, I am trying to search a file with forenames, surnames, phone numbers. I currently have:

    search(){

    dialog --inputbox "Enter contact forename" 8 20 2< ~/.addr_book

    output=`grep $forename ~/.addr_book`

    sel=$?
    case $sel in
    0) dialog --msgbox "$output" 30 50 ;;
    1) dialog --msgbox "You pressed cancel. Press the Enter key to return to menu" 8 20 ;;
    esac
    }


    Do I have to include if statements here? And the search displays all file contents rather than the name entered in the inputbox.
  2. dirk.digalow

    dirk.digalow New Member

    Messages:
    17
    Likes Received:
    9
    Trophy Points:
    3
    I've never used dialog, but are you using it correctly? It looks like you're trying to use the input of the contents of .addr_book. I also think the location of the sel=$? is wrong since it will contain the result of the grep command. I think you may need to do something like this:

    ---- SNIP ----

    dialog --inputbox "Enter contact forename" 8 20 2>~.forename

    sel=$?

    case $sel in
    0) forename=`cat ~/.forename`
    output=`grep $forename ~/.addr_book`
    dialog --msgbox "$output" 30 50;;
    1) dialog --msgbox "You pressed cancel. Press Enter key to return to menu " 8 20;;
    esac

    ---- SNIP ----
  3. gordonnmurray

    gordonnmurray New Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    yeah, you're right about what I'm trying to do. I tried your solution but it doesn't return any results.
  4. gordonnmurray

    gordonnmurray New Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    sorry, that was my fault typo. IT WORKED, THANKS SOOOOOOO MUCH!!!!!
  5. dirk.digalow

    dirk.digalow New Member

    Messages:
    17
    Likes Received:
    9
    Trophy Points:
    3
    There is appears to be a typo. The dialog line should like:

    dialog --inputbox "Enter contact forename" 8 20 2>~/.forename
  6. gordonnmurray

    gordonnmurray New Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    thanks that's great. It would be better to use if statement so that if it can't find a contact matching that that it'll return a message?
  7. gordonnmurray

    gordonnmurray New Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    I can use this to delete a contact? Using sed -I /$forename/d ~/.addr_book?
  8. dirk.digalow

    dirk.digalow New Member

    Messages:
    17
    Likes Received:
    9
    Trophy Points:
    3
    I'm not familiar with the -I option. What unix/linux are you using?
  9. dirk.digalow

    dirk.digalow New Member

    Messages:
    17
    Likes Received:
    9
    Trophy Points:
    3
    If using the "-i" it will delete any line that matches $forename.
  10. gordonnmurray

    gordonnmurray New Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    not sure what version we're using, but should that work? Can I impliment it using the method you gave me for searching?

Share This Page