grep dialog box

G

gordonnmurray

Guest
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.
 


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 ----
 
yeah, you're right about what I'm trying to do. I tried your solution but it doesn't return any results.
 
sorry, that was my fault typo. IT WORKED, THANKS SOOOOOOO MUCH!!!!!
 
There is appears to be a typo. The dialog line should like:

dialog --inputbox "Enter contact forename" 8 20 2>~/.forename
 
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?
 
I can use this to delete a contact? Using sed -I /$forename/d ~/.addr_book?
 
I'm not familiar with the -I option. What unix/linux are you using?
 
If using the "-i" it will delete any line that matches $forename.
 
not sure what version we're using, but should that work? Can I impliment it using the method you gave me for searching?
 

Members online


Top