Thanks , franklin you method worked, i knew i had to use a while loop and getline in there just didnt know the proper order
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
Tytalus
January 31, 2008, 12:52pm
3
# 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
The OP deleted his question, for clarity, this was the request:
Output of his command "./new < numbers.txt ":
hi how are you
what are you doing
or am i sleeping
the zebra ate the lion
yes sir
a banana fell
File datafile.txt:
a
the
or
Desired output:
hi how are you
what are you doing
yes sir
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