Keyword Searching

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Keyword Searching
# 1  
Old 11-10-2009
Keyword Searching

Hi all,

I am in the process of building a shell script as part of a auditing utility. It will search a specified directory for keywords and output results of the file path, and line number that the word was found on. I built a test script (shown below) that does just this, but egrep apparently does not allow MS word, excel, etc... documents to be read. I was wondering if someone could point me in an alternate direction that would allow me to search these types of documents as well? (Wordfile is a file that is create elsewhere with a list of words to search for e.g. bus)

Thanks!

Code:
cat << EOF > ${TMPDIR}/scanit
rm -f ${TMPDIR}/strings
strings "\$1" | egrep -n -i -f ${TMPDIR}/wordlist ^\d{3}-\d{2}-\d{4}$ >> ${TMPDIR}/strings
if [ -s ${TMPDIR}/strings ]
then
	echo >> ${TMPDIR}/${HOSTNAME}.o
	echo "File:  \$1" >> ${TMPDIR}/${HOSTNAME}.o
	file "\$1"  >> ${TMPDIR}/${HOSTNAME}.o
	cat ${TMPDIR}/strings >> ${TMPDIR}/${HOSTNAME}.o
fi
rm -f ${TMPDIR}/strings
EOF

HOSTNAME=`hostname`
export HOSTNHAME

if [ $# -eq 0 ]
then
	echo "You must specify the start of the directory tree to search"
	exit
fi

find $1 -type f 2> ${TMPDIR}/${HOSTNAME}_find_errors | tee ${TMPDIR}/${HOSTNAME}_filelist | \
head -100 |\
sed -e "s+^+sh -x ${TMPDIR}/scanit \"+" -e 's/$/"/' > ${TMPDIR}/scanitnow

sh -x ${TMPDIR}/scanitnow 1> ${TMPDIR}/${HOSTNAME}_scan_run 2>&1

cd ${TMPDIR}
if [ -s ${HOSTNAME}.o ]
then
	date "+%Y%M%d_%H:%m:%S: indicators found on ${HOSTNAME}" > ${HOSTNAME}_scan_results.csv
	cat ${HOSTNAME}.o >> ${HOSTNAME}_scan_results.csv
else
	date "+%Y%M%d_%H:%m:%S:  No indicators found on ${HOSTNAME}" > ${HOSTNAME}_scan_results.csv
fi

zip ${HOSTNAME}_scan.zip ${HOSTNAME}_find_errors ${HOSTNAME}_filelist ${HOSTNAME}_scan_run ${HOSTNAME}_scan_results.csv

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching exception keyword in all logs in last 5 minutes

Hello Folks , I am a new bie to the world of unix , what i am planning to do is the I have the location in server to which i am access through the putty and the location is /mt/ttlog/avccomn/logs/201901/19 and at this location the files are listed as show startjmsnode1.sh_03.out... (7 Replies)
Discussion started by: punpun26262626
7 Replies

2. Shell Programming and Scripting

Search for a Keyword in file and replace another keyword or add at the end of line

Hi I want to implement something like this: if( keyword1 exists) then check if(keyword2 exists in the same line) then replace keyword 2 with New_Keyword else Add New_Keyword at the end of line end if eg: Check for Keyword JUNGLE and add/replace... (7 Replies)
Discussion started by: dashing201
7 Replies

3. Shell Programming and Scripting

Keyword Monitor

Hello, I have a shell script. I would like to add email the curl output. I'd appreciate if you help. Thanks. #!/bin/bash while read -r URL ; do if ] ; then echo "keyword changed!!!!"|mail -s "$URL Alert!!!!" info@test.com; fi;done</root/m/url.txt . (3 Replies)
Discussion started by: tara123
3 Replies

4. Shell Programming and Scripting

paste a keyword

Hello, I have a file with a keyword ccas i want to copy the keyword once in VI and have to paste it in the same file for multiple time,let's say 700 times,i dont know hoe to do it. Kindly help me on this Regards Thelak (2 Replies)
Discussion started by: thelakbe
2 Replies

5. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

6. Solaris

find keyword

Hi, This is my first post. Please help me. I wanted to find a particular key word in the entire system not in the filename, it should be in the file content. The output should display me... <The filename>, number of times the keyword is repeated. like file1: 2 file2: 4... (3 Replies)
Discussion started by: pointers
3 Replies

7. UNIX for Dummies Questions & Answers

Using $0 and 'Function' Keyword

Hi all, I had a query on the usage of $0 in shells. I would appreciate any assistance in this. We moved from a sun solaris server to a linux server. I ran 2 different pieces on these servers and in one case, the outputs didnt change and in the other case, the outputs were different. The 2... (3 Replies)
Discussion started by: novice1324
3 Replies

8. OS X (Apple)

keyword searching of documents

Unix based fix-it needed? Platform and feature: search programs on Apple computers (Leopard or Tiger; 10.4 and above; Spotlight) Problem: the document search feature of these programs produce hits when keyword(s) used appear anywhere in the document's content. Change required: we need to... (1 Reply)
Discussion started by: Miles
1 Replies

9. Programming

Far Keyword

Hello, What is far keyword in C and for what purpose is it used??? Pls ans. thanx in advance. svh (2 Replies)
Discussion started by: svh
2 Replies

10. Shell Programming and Scripting

Keyword in perl

Hi, I want to know all the keywords in perl as well as their usage. plz provide if u have any URL regarding this. In my perl script first 2 lines are 1)use DBI; 2)require "hello.pl"; what is the use these two statements. i thought the second one may be like include . Thanks in advance.... (1 Reply)
Discussion started by: sarwan
1 Replies
Login or Register to Ask a Question