grep help, how do i rewrite this

Thanks , franklin you method worked, i knew i had to use a while loop and getline in there just didnt know the proper order :slight_smile:

Hi everyone, im trying to make the following command line shorter by introducing a script that join up all the grep commands

./new1a < numbers.txt | grep -i -v '^a ' | grep -i -v '^the ' | grep -i -v '^or ' | sort -f

How would I go about merging all the greps into a scripe and putting all the words that should be excluded into a data file

With awk you can do something like this:

awk '
FNR==NR{arr[$1]=$1;next}
!arr[$1]{print}
' "datafile.txt" "numbers.txt"

Regards

#  cat numbers.txt

hi how are you
what are you doing
or am i sleeping
the zebra ate the lion
yes sir
a banana fell

#  cat exclude.file
^a
^the
^or



#   /usr/xpg4/bin/grep -v -f exclude.file numbers.txt

hi how are you
what are you doing
yes sir

alright ll give it a try

The OP deleted his question, for clarity, this was the request:

Try this:

./new < numbers.txt | awk '
  BEGIN{while(getline < "datafile.txt" > 0 ) {
    arr[$1]=$1
  }
  close("datafile.txt")
}
!arr[$1]{print}
'

Regards

Thanks I almost got the same thing, just had some syntax issue that you have corrected . Thank you once again :slight_smile: