{"id":4747,"date":"2017-04-02T11:58:51","date_gmt":"2017-04-02T09:58:51","guid":{"rendered":"http:\/\/speefak.spdns.de\/oss_lifestyle\/?p=4747"},"modified":"2024-06-02T13:07:45","modified_gmt":"2024-06-02T11:07:45","slug":"findgrep-volltextsuche-fuer-die-shell","status":"publish","type":"post","link":"https:\/\/speefak.spdns.de\/oss_lifestyle\/findgrep-volltextsuche-fuer-die-shell\/","title":{"rendered":"Findgrep &#8211; Volltextsuche f\u00fcr die Shell"},"content":{"rendered":"<p>Vor einiger Zeit fand ich ein Script, dass die Volltextsuche via Shell erm\u00f6glicht 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.<\/p>\n<pre class=\"lang: decode:true\">#!\/bin\/bash\r\n# FINDGREP INFO ########################\r\nPROGRAMINFO=\"findgrep version 6.\r\nThis Script simplifies the recursive search of any given string in a given directory.\r\nIt combines find and grep. Results are logged for later viewing and analyzing.\r\nfindgrep remembers directories and search strings for following searches.\"\r\n\r\nPROGRAMINFO2=\"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.\"\r\n\r\n# CHANGELOG #############################\r\n# Script now remembers directories and search strings. \r\n# Logfile now moved to \/tmp. \r\n# Changed to more userfriendly interface. \r\n# Added many comments for better script reading.\r\n\r\n# DEBUG MODE ############################\r\n# set -x\t\t\t\t\t# uncomment for debugging\r\n\r\n# DEFINING SESSION SETTINGS #############\r\nROOTDIR=\"$HOME\/.findgrep\"\t\t# place to store files\r\nSAVEDIR=\"\/$ROOTDIR\/remember.dir\"\t# last search directory\r\nSAVESTRING=\"\/$ROOTDIR\/remember.string\"\t# last search string\r\n#########################################\r\nif [ ! -f $ROOTDIR ]\t\t\t# file storage directory exists?\r\n\tthen\r\n\tmkdir $ROOTDIR\t\t\t# if not: create directory\r\nfi\r\n#########################################\r\nif [ ! -f $SAVEDIR ]\t\t\t# last search directory defined?\r\n\tthen\r\n\techo $HOME &gt; $SAVEDIR\t\t# if not, set to: home directory\r\nfi\r\n#########################################\r\nif [ ! -f $SAVESTRING ]\t\t\t# last search string defined?\r\n\tthen\r\n\techo $USER &gt; $SAVESTRING\t# if not, set to: user name \r\nfi\r\n\r\n# VARIABLES #############################\r\nPROGNAME=\"findgrep v6\"\t\t\t# name of program\r\nSAVEFILE=\"$ROOTDIR\/.findgrep.log\"\t# log file location\r\nSEARCHDIR=\"`cat $SAVEDIR`\"\t\t# load search directory\r\nSEARCHSTRING=\"`cat $SAVESTRING`\"\t# load search string\r\nDIVIDER=\"--------------------------------------------------\" # better viewing\r\n\r\n# FUNKTION HEADER #######################\r\nHEADER () {\r\nclear\r\necho \"  __ _           _                      \r\n \/ _(_)_ __   __| | __ _ _ __ ___ _ __  \r\n| |_| | '_ \\ \/ _. -- _. | '__\/ _ \\ '_ \\ \r\n|  _| | | | | (_| | (_| | | |  __\/ |_) |\r\n|_| |_|_| |_|\\__,_|\\__, |_|  \\___| .__\/ \r\n                   |___\/         |_|    \" | grep --color .\r\n\r\necho \"   Recursive Text String Search Tool\"\t| grep --color .\r\necho\r\n}\r\n\r\n# CHOOSE DIRECTORY TO SEARCH ############\r\nHEADER\r\necho \"Search in Directory:\t$SEARCHDIR ?\" \t| grep --color ? \r\necho \"If OK, press ENTER. To change please enter new path.\"\r\n\r\nread -e INPUT\t\t\t\r\n\tif [ \"$INPUT\" != \"\" ]\t\r\n\t\tthen echo $INPUT &gt; $SAVEDIR\r\n\t\tSEARCHDIR=\"$INPUT\"\r\n\tfi\r\nHEADER\r\necho \"Searching in:\t\t$SEARCHDIR \"\t| grep --color $SEARCHDIR\r\n\r\n# CHOOSE TEXTSTRING TO SEARCH ####################\r\necho \"Search for:\t\t$SEARCHSTRING ?\"\t| grep --color ?\r\necho \"if OK, press ENTER. To change please enter new searchstring.\"\r\nread -e INPUT2\r\n\tif [ \"$INPUT2\" != \"\" ]\t\r\n\t\tthen echo $INPUT2 &gt; $SAVESTRING\r\n\t\tSEARCHSTRING=\"$INPUT2\"\r\n\tfi\r\necho \"$SEARCHSTRING\"\t\t\t| grep --color .\r\n\r\n# SUMMARY ########################################\r\nHEADER\r\necho \"SUMMARY:\"\r\necho \"Searching in:\t$SEARCHDIR\"\t| grep --color $SEARCHDIR \r\necho \"Searching for: \t$SEARCHSTRING\"\t| grep --color $SEARCHSTRING\r\necho \"Logging to:\t$SAVEFILE\"\t| grep --color $SAVEFILE\r\necho $DIVIDER\r\necho \"Now starting recursive search for $SEARCHSTRING in $SEARCHDIR...\"\r\necho $DIVIDER\r\necho \"SEARCH RESULTS:\" \t\t\t| grep --color \"SEARCH RESULTS\"\r\nexport GREP_COLOR=\"31\"\r\n\r\n# EXECUTE #########################################\r\nfind $SEARCHDIR -type f -exec grep -i $SEARCHSTRING --exclude=$SAVEFILE \/dev\/null {} \\; 2&gt; \/dev\/null | tee $SAVEFILE | grep -i --color $SEARCHSTRING\r\n\r\n# DISPLAY RESULTS ################################\r\necho $DIVIDER\r\nexport GREP_COLOR=\"01;31\"\t# fett, rot\r\necho \"Search in $SEARCHDIR:\t\tfinished\"\t| grep --color .\r\necho \"Found \\\"$SEARCHSTRING\\\":\t\t\t`cat $SAVEFILE | wc -l`\"\t| grep --color .\r\necho \"Results saved to: \t\t$SAVEFILE\"\t| grep --color .\r\necho $DIVIDER\r\necho $PROGRAMINFO2\r\necho $DIVIDER\r\nexit<\/pre>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-2821 alignleft\" src=\"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-content\/uploads\/2014\/08\/CC_BY_NC_SA.png\" alt=\"CC_BY_NC_SA\" width=\"65\" height=\"23\" \/><span style=\"font-size: 10pt;\">by Speefak <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vor einiger Zeit fand ich ein Script, dass die Volltextsuche via Shell erm\u00f6glicht 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. #!\/bin\/bash # FINDGREP INFO ######################## PROGRAMINFO=&#8221;findgrep version 6. This Script simplifies the recursive search of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,53,54],"tags":[],"class_list":["post-4747","post","type-post","status-publish","format-standard","hentry","category-bash","category-scripte","category-shell-programme"],"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"speefak","author_link":"https:\/\/speefak.spdns.de\/oss_lifestyle\/author\/speefak_oss\/"},"rttpg_comment":1,"rttpg_category":"<a href=\"https:\/\/speefak.spdns.de\/oss_lifestyle\/category\/bash\/\" rel=\"category tag\">Bash<\/a> <a href=\"https:\/\/speefak.spdns.de\/oss_lifestyle\/category\/scripte\/\" rel=\"category tag\">Scripte<\/a> <a href=\"https:\/\/speefak.spdns.de\/oss_lifestyle\/category\/shell-programme\/\" rel=\"category tag\">Shell<\/a>","rttpg_excerpt":"Vor einiger Zeit fand ich ein Script, dass die Volltextsuche via Shell erm\u00f6glicht 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. #!\/bin\/bash # FINDGREP INFO ######################## PROGRAMINFO=\"findgrep version 6. This Script simplifies the recursive search of&hellip;","_links":{"self":[{"href":"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-json\/wp\/v2\/posts\/4747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-json\/wp\/v2\/comments?post=4747"}],"version-history":[{"count":0,"href":"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-json\/wp\/v2\/posts\/4747\/revisions"}],"wp:attachment":[{"href":"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-json\/wp\/v2\/media?parent=4747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-json\/wp\/v2\/categories?post=4747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/speefak.spdns.de\/oss_lifestyle\/wp-json\/wp\/v2\/tags?post=4747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}