Skip to content

Instantly share code, notes, and snippets.

@vitonzhangtt
Created November 12, 2018 07:00
Show Gist options
  • Save vitonzhangtt/cd92378c005d8e70973bef0e2849f37b to your computer and use it in GitHub Desktop.
Save vitonzhangtt/cd92378c005d8e70973bef0e2849f37b to your computer and use it in GitHub Desktop.
Find target string from the files that name match the expression.
#!/bin/bash
if [ $# -ne 3 ]; then
echo "The number of arguments must be 3"
exit 1
else
echo "Finding..."
fi
DIRECTORY=$1
NAME=$2
TARGET_STRING=$3
echo $DIRECTORY
echo $NAME
echo $TARGET_STRING
echo ====================================
FILES=`find $DIRECTORY -type f -name "$NAME"`
#echo $FILES
for file in $FILES; do
echo "starting scanning ${file}"
cat -n $file | grep ${TARGET_STRING}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment