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.
 


D

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

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

gordonnmurray

Guest
yeah, you're right about what I'm trying to do. I tried your solution but it doesn't return any results.
 
G

gordonnmurray

Guest
sorry, that was my fault typo. IT WORKED, THANKS SOOOOOOO MUCH!!!!!
 
D

dirk.digalow

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

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

gordonnmurray

Guest
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?
 
G

gordonnmurray

Guest
I can use this to delete a contact? Using sed -I /$forename/d ~/.addr_book?
 
D

dirk.digalow

Guest
I'm not familiar with the -I option. What unix/linux are you using?
 
D

dirk.digalow

Guest
If using the "-i" it will delete any line that matches $forename.
 
G

gordonnmurray

Guest
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


Latest posts

Top