
match works, don't match doesn't
Quote:
>The following is supposed to search an input file and produce 2 output
>files. The input file consists of text lines of two fields, delimited
>by whitespace. The first output file is to contain those lines in the
>input file where any one of the variable strings match the first
>field. (This works.) The second output file is to contain those lines
>where the variable strings do not match, i.e. all the lines in the
>input file except those found with the first search. (This doesn't
>work.)
>###command-line parameter placed in variable.###
> searchdot="\.$1"
> searchexact=$1
>awk '{IGNORECASE=1} $1 ~ /'^"$searchexact"$'/ || /'"$searchat"'/ ||
>/'"$searchdot"'/ { print $0 }' input.file > output1.file
>awk '{IGNORECASE=1} $1 !~ /'^"$searchexact"$'/ || /'"$searchat"'/ ||
>/'"$searchdot"'/ { print $0 }' input.file > output2.file
>Any help gratefully accepted.
This is not the normal way to pass shell variables to awk. See man awk
Bassically you'd do something like:
awk '$1 ~ /var1/ ' var1=$searchexact input.file > output1.file
which is a simplified version of what you had to give you an idea.
Put the IGNORECASE thing in a BEGIN section, and if you only want to
print the entire line the { print $0 } is unnecessary.
Are you sure that you have the right logic for what you're trying to
do in the second case? I'd try adding parentheses to insure that
things are grouped properly to get the proper precedence of operators.
Just some quick thoughts, I haven't tried any of it.
BTW, you could do this with egrep using the -i and -v options as
appropriate, I believe. Egrep allows the OR operator "|".
Chuck Demas
Needham, Mass.
--
Eat Healthy | _ _ | Nothing would be done at all,
Die Anyway | v | That no one could find fault with it.