how to make menu of result from egrep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to make menu of result from egrep
# 1  
Old 08-17-2008
how to make menu of result from egrep

hi,
im just starting with scripting , i have de following situation
im doing a search in a data folder with egrep

egrep -i "title.regu." `find . -name "*.dat"`

the result is :

./20080816212245/index.dat:title Regular Expressions
./20080811212216/index.dat:title Reguliere Expressies Tutorial
./20080815173529/index.dat:title Reguliere Expressies handout

Now i want to create a simple menu of the result, so it's possible to choose from
above results.( so for above result, you get a menu of 3 options), then when i choose
1 for example (the first outcoming result), is must go to folder called 20080816212245, (this is de first of the result, then in that folder is file index.html,
(so cd 20080816212245 then nano index.html)

Is there an easy way to do this?.
ps im have no knowledge of sed e.t.. can this be done without?

thank a lot.
# 2  
Old 08-17-2008
egrep -i "title.regu." `find . -name "*.dat"` > output

cat $output | while read line
do

dir=$( echo $line | cut -d / f2)

cd dir

# you will reach in directory and can execute whatever you want then.

done
# 3  
Old 08-17-2008
Try this as well.

Code:
select pick in $(egrep -i "title.regu." $(find . -name "*.dat")); do
  echo "$pick"
done

The $(...) construct is equivalent to `...` but it's easier to read and easier to nest.

Prat007 could avoid the use of Useless Cats and temporary files. Also I don't get the benefit of the cd -- basically all Unix commands can cope with a complete file name (and there's a dash missing before the -f option in the cut, but let's not dwell on that):

Code:
egrep -i "title.regu." `find . -name "*.dat"` |
while read line; do
  echo "$line"
done

This doesn't produce a menu, though, it just loops over the matches.
# 4  
Old 08-21-2008
Hi

both thanks, last days im playing arround with this solutions, and
it seems very good, one last issue im facing with is the space in the description i generate a seperate menu option, so i mean Reguliere expressie tutorial will generate 3 option's 1) Reguliere , 2) Expressie , 3) tutorial.
Is this easy to handle and generate 1) Reguliere expressie tutorial instead.

Thanks again
regards
# 5  
Old 08-21-2008
Try this.

Code:
#!/bin/sh
OLDIFS=$IFS
IFS='
'
select pick in $(... whatever commands ...); do
  echo "$pick"
done
IFS=$OLDIFS

By manipulating $IFS we tell the shell to use different rules for splitting up a list of arguments; setting IFS to a newline means split on newlines. You could put other characters, such as colon, in there as well. (In your case I imagine you would want to ditch everything before the first colon with cut -d: -f2- instead, though.)
# 6  
Old 08-21-2008
Although era's solution works perfectly there is also another way of creating menus using the dialog command with the --menu option.

dialog is a program which uses the ncurses API to create dialog boxes for shell scripts.

Here's an example of what you can achieve:
Code:
dialog --menu "Hello world\nstuff stuff stuff" 12 50 12 "Menu1" "desc1" "Menu2" "desc2" "Menu3" "desc3" "Menu4" "desc4"

There are lots of example uses of dialog.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Gnome 3.28.3 menu item dissapears under the system menu

I installed CentOS 8 with Gnome 3.28.2 and I noticed that the "switch user" menu item disappeared from under the system menu of Gnome classic (Both X11 & Wayland). I checked google and this problem seems to have a history going back several releases of Gnome. Unfortunately, I never found a... (1 Reply)
Discussion started by: bodisha
1 Replies

2. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

3. Shell Programming and Scripting

Egrep how to make sure string is after 5 comma

Hello, Need help... using egrep how do I make sure string is after 5th comma example: a,b,c,d,e,f,g,h,i Suppose i want to search letter f but want to make sure it is after 5th comma. Is there any way to check string is after 5th comma? Thanks !! (9 Replies)
Discussion started by: vegasluxor
9 Replies

4. Shell Programming and Scripting

Need help in create menu with 3 sub menu using the case command

hi all i am a newbie to this is there any examples on creating a main menu with 3 sub menu main menu -> option a , b and c a menu -> option 1 ,2 and 3 b menu -> option 1 ,2 c menu -> option 1 ,2 i am getting headache as my code kept getting unexpected EOF ---------- Post... (0 Replies)
Discussion started by: chercm
0 Replies

5. Shell Programming and Scripting

Menu in Menu script issue

Problem: I am trying to create a menu in a menu script and I am running into an issue with the calculator portion of the script. I am first presented with the ==Options Menu== which all 5 options working correctly. Now comes the fun part. I select option 1 which takes me to my ==Calculator... (1 Reply)
Discussion started by: iDdraig
1 Replies

6. UNIX for Dummies Questions & Answers

search ")" with egrep - egrep: syntax error

Hi Guys, we have a shell script which basically query the Database which retrieves huge data and use the data with "egrep" . Now there is some data which contains characters like "abc)" and the same is used like below : "egrep (.+\|GDPRAB16\|GDPR/11702 96 abc)\|$ temp.txt" now while... (7 Replies)
Discussion started by: sagarjani
7 Replies

7. Shell Programming and Scripting

using egrep to get result

Hi all, Can egrep using AND OR ?, like egrep -i "title.$1" AND "category.$2" ./home.... I want to give two search criteria, the files where egrep is seaching in for example looks like below rows. title this is an test category space (command line input) $1 script.sh this space ... (6 Replies)
Discussion started by: tvrman
6 Replies

8. Shell Programming and Scripting

egrep/grep result of more files

hi , I'm new at unix bash scripting, im playing a little bit with egrep/grep. I have serveral files and i do a search on those files, like "aki", the result is many rows outcoming and serveral of them are dubble because aki wil come more than ones in a file, how can i get a result that it... (3 Replies)
Discussion started by: tvrman
3 Replies

9. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies

10. UNIX for Dummies Questions & Answers

egrep counting every 2 lines of result as 1

Hi, Can someone help me count this line: Say I have a file (file1.txt) that contains below: 11/16 13:08:19.5436 18096 --- Generating a <reading> event 11/16 13:08:19.7784 18096 ---- Sending a <writing> event 11/16 13:08:37.4516 18096 --- Generating a <reading> event 11/16... (1 Reply)
Discussion started by: Orbix
1 Replies
Login or Register to Ask a Question