Simple bash script for searching keyword in the given directories linux

Simple bash script for searching keyword in the given directories linux

I find myself using grep over and over again for searching some keyword in the same directories. I write this, very simple and almost single usage script to accomplish the task

#! /bin/bash

# Find the given keywork in the given directories #

if [ $# -lt 1 ]; then
    echo $"No Keyword is provided"
    echo $"Usage: ./search_keyword.sh needle"
    exit
fi

keyWord=$1

#list where you would want to look inside the directory

directories="dir1 dir2 dir3 dir4 dir5"
for directory in $directories
do
    if [ -d $directory ]; then
        echo $"Serching in $directory"
        grep -ir --color $keyWord $directory
    else
        echo $"#### Directory $directory does not exist ####"
    fi
done

See how you would solve these known algorithm problems

Java solution for checking anagram strings – tell if phrases are anagrams

Array reversal in Recurrsion

String Ordered Permutation Algorithm Problem

Implementing tokenizer and adding tokens to the linked list

Check if there are three numbers a, b, c giving a total T from array A

Find the pairs that makes K Complementary in the given array java solution

binary tree problems with solution

Find the first occurence of number in the sorted array

Find longest palindrom from sequence of characters

Kadane’s algorithm in C – Dynamic Programming

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*