Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

  1. Follow us on twitter - we shoot all of our new original content out as well as random messages. https://twitter.com/linuxdotorg
    Dismiss Notice

grep dialog box

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

  1. Hi, I am trying to search a file with forenames, surnames, phone numbers. I currently have:


    (Log in to hide this advertisement)

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

    output=`grep $forename ~/.addr_book`

    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 ;;

    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 Guest

    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


    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;;

    ---- SNIP ----
  3. yeah, you're right about what I'm trying to do. I tried your solution but it doesn't return any results.
  4. sorry, that was my fault typo. IT WORKED, THANKS SOOOOOOO MUCH!!!!!
  5. dirk.digalow

    dirk.digalow Guest

    There is appears to be a typo. The dialog line should like:

    dialog --inputbox "Enter contact forename" 8 20 2>~/.forename
  6. 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. I can use this to delete a contact? Using sed -I /$forename/d ~/.addr_book?
  8. dirk.digalow

    dirk.digalow Guest

    I'm not familiar with the -I option. What unix/linux are you using?
  9. dirk.digalow

    dirk.digalow Guest

    If using the "-i" it will delete any line that matches $forename.
  10. 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