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 <some.h>" | awk -F: '{print $1}' | xargs grep "#include <another.h>"

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 <some.h>. 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

I'm also open to better suggestions! :)

#!/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.

Glad you got it working :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.