954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Shell script and awk

This is probably just due to my quotes, but I'm trying to get the following script up and running:

This is my command line:
find ./ -type f | xargs grep "#include " | awk -F: '{print $1}' | xargs grep "#include "

I'm trying to find a nested header that is giving me compiler errors (struct redefinition). I hate typing that command in for obvious reasons. However every time I run it in a script the $1 keeps expanding to: #include . Which is not what I want. Any suggestions?

Thanks.

#!/bin/bash

PWD=`pwd`

LIST=`find $PWD -type f | xargs | grep $1 | awk -F: '{print $1}'`

for found in $LIST do
grep $2 $found
done

exit 0

sgentry6
Newbie Poster
3 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

I'm also open to better suggestions! :)

sgentry6
Newbie Poster
3 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

#!/bin/bash

if [ $# -ne 2 ]
then
echo "Usage $0 searchTerm1 searchTerm2"
exit $USAGE

USAGE=1
PWD=`pwd`
LIST=`find $PWD -type f | xargs grep -l $1`


else
for found in $LIST
do
grep $2 $found >& /dev/null
if [ $? -eq 0 ]
echo $found
fi
done
fi

exit 0


Reading the man page to grep should be a requirement. It already had the option I needed (just getting the filename). I will clean this thing up, and add the ability to search for as many terms as you need.

sgentry6
Newbie Poster
3 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

Glad you got it working :)

Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You