The following code will create a function in bash that accepts two parameters (1: the place to search in, 2: the value to search for).
You can place it in your ~/.bashrc file to have it available whenever you open a bash shell.
#1. Copy/paste the below lines in your .bashrc
#takes 2 parameters (1: the haystack to search in, 2: the needle)
# Will print out the files and the lines that contain the needle
xfind(){
FIND_VAR="$2";
STACK="$1";
if [ -f "$STACK" ] || [ -d "$STACK" ]; then
find "$STACK" \
-exec grep --color "$FIND_VAR" -sl '{}' \; \
-exec grep "$FIND_VAR" -s '{}' \;
else
echo "ERROR: No file or folder with the name '$STACK' exist";
fi
}
#2. Run source ~/.bashrc -- to reload
The following code will use as input one column from a CSV file, and for each element in the column, it will perform a full-text search in a folder to find all files that contain that element. #!/bin/bash #Execution parameters # 1 - the folder to look in for the…
Assuming you have a lot of files and you need to find all files that contain a certain string value, you can check them all automatically using the following command. Method 1 - Using find -exec Using the exec flag of find, you can process all files even those that…
#1. Copy/paste the below lines in your .bashrc tailf-with-colors () { if [ -z "$1" ] ; then echo "Please specify a file for monitoring" return fi tail -f $1 | awk ' {matched=0} /INFO:/ {matched=1; print "\033[0;37m" $0 "\033[0m"} # WHITE …