Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for "not something"

Status
Not open for further replies.

KarveR

MIS
Dec 14, 1999
2,065
GB
Hi all, a quick one.

I have a bunch of files, and the line I'm looking for begins NAD CA and contains 100BAY, but I need to be able to serch a bucnh of these to find which ones Don't contain the line starting NAD CA or having the line NAD CA which isn't
NAD CA 100BAY

How please.

open to awk, sed , grep or any other available voodoo or black magics.





______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
You can use "grep -v" to locate strings which DO NOT contain the matching pattern. I'm not sure if that fully satisfies your criteria, but you should be able to work that into a script sort of like this:
Code:
for i in `cat flist`
do
GOTONE=`cat $i|grep -v "^NAD CA 100BAY"`
if [ "$GOTONE" > "" ]
   then echo "File $i has bad lines">>logfile
fi
done
 
Thanks for the reply, the -v shows me every line except the one I need to identify the file.

Got there tho the hard way I guess:
Code:
#!/bin/sh
#echo "$1"
#set -x

if [ $# -lt 2 ] ; then
echo "`basename $0` - usage"
echo "Require file mask and Month abbreviation (eg Oct) arguments"
else

FILES=(`ls -l *"$1"|awk -v mm="$2" '{ if ($6==mm) print $9}'`)
i=0
while [ $i -lt ${#FILES[@]} ]
do
        echo "${FILES[$i]}: "
        result=`grep -hc "^NAD CA  100BAY" ${FILES[$i]}`
        if [ $result -eq 0 ] ; then
                SCJ=`grep -hc "^NAD CA  100SCJ" ${FILES[$i]}`
                if [ $SCJ -eq 1 ] ; then
                	echo "${FILES[$i]} is 100SCJ" >> SCJ.log
                else
                	echo "${FILES[$i]} Not correct" >> Error_log.txt
                	awk '/^RFF IL|^NAD CA|^NAD DP/' ${FILES[$i]} >> Error_log.txt
                	echo "------------------------------------------------------" >> Error_log.txt
                fi
        else
                awk '/^RFF IL|^NAD CA|^NAD DP/' ${FILES[$i]}
                echo "------------------------------------------------------"
        fi
        i=`expr $i + 1`

        done
fi

Log files not destined for us to SCJ.log, og files with errors to Error_log and display everything else for a quick visual check.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Code:
grep -L "^NAD CA 100BAY" *.txt
with grep (GNU grep) 2.5.1

and for recursive search of subdirs:
Code:
find ./ -name "*.txt" -exec grep -L "^NAD CA 100BAY" {} \;

(assuming a filepattern *.txt)

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top