6th Jan
#!/bin/sh echo "Shell Script to find particular string in a given log file" if [ "$#" -ne 2 ]; then echo "USAGE:LOG_PATH INPUT_FILE WORDSFILE" exit 1 fi echo "Script Execution Started ......." count=0; init=0; words=""; while read -r line; do if [ -z "$line" ] ; then echo "empty line"; else if [ "$count" -eq "$init" ]; then words="$words""$line" else words="$words""\|"$line"" fi count=$((count+1)) fi done < $2 if [ ! -d temp ]; then mkdir temp fi current_dir=`pwd` while read -r line; do for file in $line*; do if [ -e temp.log ]; then >temp.log fi filename=$(echo "$file" | sed 's,/,:-,g') tempname=${file##*/}'_temp' sed -e 's/^/'${filename}'-/' $file >temp.log diff temp.log $current_dir/temp/$tempname | grep "<" | sed 's/^<//g' | sed "s/^.//g" >$current_dir/temp/$tempname grep -e "$words" $current_dir/temp/$tempname >>result1.log echo "search completed in $file" done done < $1 sort result1.log | uniq -c >>result.log sed -i -e 's/:-/\//g' result.log sed -i -e 's/:-/\//g' result.log rm result1.log rm temp.log echo "script completed"
No comments:
Post a Comment