Vor einiger Zeit fand ich ein Script, dass die Volltextsuche via Shell ermöglicht und dabei die letzten Eingaben wie Suchmuster und Pfad speichert. Zum Einsatz kommen dabei find, grep und figlet. Ich konnte den Author des Scriptes nicht mehr ermitteln.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
#!/bin/bash # FINDGREP INFO ######################## PROGRAMINFO="findgrep version 6. This Script simplifies the recursive search of any given string in a given directory. It combines find and grep. Results are logged for later viewing and analyzing. findgrep remembers directories and search strings for following searches." PROGRAMINFO2="To change the path for logging of queries, please edit \$SAVEFILE in this script. Searches are case insensitive by default. Written by LinuxNetzer. www.netz10.de. contact: linuxnetzer-*-aet-*-netz10.de. findgrep v6 is released under GPL v3." # CHANGELOG ############################# # Script now remembers directories and search strings. # Logfile now moved to /tmp. # Changed to more userfriendly interface. # Added many comments for better script reading. # DEBUG MODE ############################ # set -x # uncomment for debugging # DEFINING SESSION SETTINGS ############# ROOTDIR="$HOME/.findgrep" # place to store files SAVEDIR="/$ROOTDIR/remember.dir" # last search directory SAVESTRING="/$ROOTDIR/remember.string" # last search string ######################################### if [ ! -f $ROOTDIR ] # file storage directory exists? then mkdir $ROOTDIR # if not: create directory fi ######################################### if [ ! -f $SAVEDIR ] # last search directory defined? then echo $HOME > $SAVEDIR # if not, set to: home directory fi ######################################### if [ ! -f $SAVESTRING ] # last search string defined? then echo $USER > $SAVESTRING # if not, set to: user name fi # VARIABLES ############################# PROGNAME="findgrep v6" # name of program SAVEFILE="$ROOTDIR/.findgrep.log" # log file location SEARCHDIR="`cat $SAVEDIR`" # load search directory SEARCHSTRING="`cat $SAVESTRING`" # load search string DIVIDER="--------------------------------------------------" # better viewing # FUNKTION HEADER ####################### HEADER () { clear echo " __ _ _ / _(_)_ __ __| | __ _ _ __ ___ _ __ | |_| | '_ \ / _. -- _. | '__/ _ \ '_ \ | _| | | | | (_| | (_| | | | __/ |_) | |_| |_|_| |_|\__,_|\__, |_| \___| .__/ |___/ |_| " | grep --color . echo " Recursive Text String Search Tool" | grep --color . echo } # CHOOSE DIRECTORY TO SEARCH ############ HEADER echo "Search in Directory: $SEARCHDIR ?" | grep --color ? echo "If OK, press ENTER. To change please enter new path." read -e INPUT if [ "$INPUT" != "" ] then echo $INPUT > $SAVEDIR SEARCHDIR="$INPUT" fi HEADER echo "Searching in: $SEARCHDIR " | grep --color $SEARCHDIR # CHOOSE TEXTSTRING TO SEARCH #################### echo "Search for: $SEARCHSTRING ?" | grep --color ? echo "if OK, press ENTER. To change please enter new searchstring." read -e INPUT2 if [ "$INPUT2" != "" ] then echo $INPUT2 > $SAVESTRING SEARCHSTRING="$INPUT2" fi echo "$SEARCHSTRING" | grep --color . # SUMMARY ######################################## HEADER echo "SUMMARY:" echo "Searching in: $SEARCHDIR" | grep --color $SEARCHDIR echo "Searching for: $SEARCHSTRING" | grep --color $SEARCHSTRING echo "Logging to: $SAVEFILE" | grep --color $SAVEFILE echo $DIVIDER echo "Now starting recursive search for $SEARCHSTRING in $SEARCHDIR..." echo $DIVIDER echo "SEARCH RESULTS:" | grep --color "SEARCH RESULTS" export GREP_COLOR="31" # EXECUTE ######################################### find $SEARCHDIR -type f -exec grep -i $SEARCHSTRING --exclude=$SAVEFILE /dev/null {} \; 2> /dev/null | tee $SAVEFILE | grep -i --color $SEARCHSTRING # DISPLAY RESULTS ################################ echo $DIVIDER export GREP_COLOR="01;31" # fett, rot echo "Search in $SEARCHDIR: finished" | grep --color . echo "Found \"$SEARCHSTRING\": `cat $SAVEFILE | wc -l`" | grep --color . echo "Results saved to: $SAVEFILE" | grep --color . echo $DIVIDER echo $PROGRAMINFO2 echo $DIVIDER exit |
by Speefak
Danke fürs Teilen. Dieses Programm ist super!