#! /bin/bash #Get the current working directory current_dir=$(pwd) #Give the new directory path where file will be copied new_dir=$current_dir/allfiles #verify if the directory already exists or not if test -d "$new_dir"; then echo Directory already exists else mkdir $new_dir fi #Loop through files in the current directory and copy the files that has the keyword in the new directory for i in $current_dir/*; do if test -f $i then keydata=$(grep -i "hello" $i) if [ -z "$keydata" ]; then echo "Keyword not found in file "$i else echo "Keyword found in file: "$i cp $i $new_dir fi else echo $i is not a file here fi done