what im trying to do with the above is, i want to print numbers that are in the GOODNUMBERS variable IF AND ONLY IF they are not in the BADNUMBERS variable.
@Srinishoo:
The variable limitation is not in awk, nor is it a limitation of the shell, but rather an OS limitation determined by the configuration variable ARG_MAX ( getconf ARG_MAX ) .
Some versions of awk limit the length of strings held in variables (as well as the maximum length of lines to be read) to LINE_MAX bytes (the awk on OS X is one example of this). (The value of LINE_MAX on your system can be found using getconf LINE_MAX , but is frequently 2048.)
If $GOODNUMBERS and $BADNUMBERS expand to lists shorter than LINE_MAX bytes, running the loop in Scrutinizer's suggested shell script could well be faster than exec'ing awk and interpreting the equivalent loop(s) in an awk script.
Your requirements aren't clear as to whether or not duplicated values in $GOODNUMBERS are supposed to be trimmed to a list of unique numbers, or if duplicated input numbers are to be duplicated in the output. If you want only unique numbers in your output and your list of numbers is too long for your version of awk to accept as a variable, you could try something like:
#!/bin/ksh
GOODNUMBERS="1 2 3 4 5 6 3 3 34 34 5 66 12"
BADNUMBERS="7 3 12 5 66"
printf '%s\n' $BADNUMBERS 'EOF' $GOODNUMBERS | awk '
/EOF/ { good = 1; next }
!good { b[$0]; next }
!($0 in b) && !($0 in g) {
g[$0]; print
}'
which produces:
1
2
4
6
34
Note that even though this output happens to be sorted, this script can mangle the order of values output.
This was tested using the Korn shell, but will also work with bash or any other shell that that uses POSIX standard shell syntax.
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk .