Skip to content

Instantly share code, notes, and snippets.

@Rust1667
Created November 7, 2022 22:51
Show Gist options
  • Save Rust1667/bc7370b934bfbe0532066d9b6e800fca to your computer and use it in GitHub Desktop.
Save Rust1667/bc7370b934bfbe0532066d9b6e800fca to your computer and use it in GitHub Desktop.
Script for Linux, using Grep. It searches recursively all the .md files inside a folder. It uses a regular expression, so the input is 2 words, and it returns the lines containing both of those (one could be empty). Useful to search through a massive database of links saved in markdown.
# SETTINGS
readonly docsRoute=~/Documents/search-repos
# CODE
doAsearch () {
echo -------------------------------------------------------------------------------------------------------------------
echo New search. Enter the search terms [word1 and word2]:
echo word1:
read word1
echo word2:
read word2
regExSearchString="$word1.*$word2|$word2.*$word1"
#echo Printing all the lines than contain [$word1] and [$word2].
echo
grep --color=always -Hrn -i -E $regExSearchString --include *.md | awk '{print $0,"\n"}'
doAsearch
}
cd $docsRoute
pwd
doAsearch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment