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.
 


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

gordonnmurray

Guest
sorry, that was my fault typo. IT WORKED, THANKS SOOOOOOO MUCH!!!!!
 
OP
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
 
OP
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?
 
OP
G

gordonnmurray

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

dirk.digalow

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

dirk.digalow

Guest
If using the "-i" it will delete any line that matches $forename.
 
OP
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?
 
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Staff online


Top