file content as a part of an if-statement

Hello,
I have following problem.
I have the result of a database request. I preparated the result via sed, etc. as a string in a file.
The string in the file is:
($3==1 || $3==2 || $3==3 || $3==4)
Now I want to use the String as a command in an if-statement.
So I assigned the string to a variable:
ABC=$(<dir/file)

So far - so good:
echo $ABC gives me as a result: ($3==1 || $3==2 || $3==3 || $3==4)

But with nawk it doesn't work.

For clarification: If I would use the string directly (and so static), my awk would be written like here:

#If we find the values 1,2,3 or 4 in column 3, so change the value in column 4 into 10 in the relevant rows.
nawk '{FS=";";OFS=";"; if ($3==1 || $3==2 || $3==3|| $3==4) {$5=10}; print $0}' dir/file1.txt > dir/file2.txt

But dynamically it doesn't work. My idea was following:

nawk '{FS=";";OFS=";"; if ($ABC) {$5=10}; print $0}' dir/file1.txt > dir/file2.txt

I tested everything, with echo $ABC, cat, different brackets... but without success.

Is anybody able to help me and explain to me what I have to change, please?

Thanks a lot and Kind Regards
Dr_Aleman

Can you try by assigning $ABC to an awk variable..

nawk -v var="$ABC" '{FS=";";OFS=";"; if (var) {$5=10}; print $0}' dir/file1.txt > dir/file2.txt

or directly w/o awk variable

nawk '{FS=";";OFS=";"; if ('"$ABC"') {$5=10}; print $0}' dir/file1.txt > dir/file2.txt
1 Like

Use -v option with awk.

nawk -v var=$ABC 'BEGIN{FS=";";OFS=";"} {if (var) {$5=10}; print $0}' dir/file1.txt > dir/file2.txt
1 Like

Thank you guys for the quick answers.
@Pravin27: With your solution I got an error after execution:

 
nawk: syntax error at source line 1
 context is
         >>> || <<<
nawk: bailing out at source line 1

@Michaelrozar: your first suggestion changed all of the values in the column into 10 (not only the relevant rows with the 1,2,3 and 4).
But your second suggestion worked perfectly:

nawk '{FS=";";OFS=";"; if ('"$ABC"') {$5=10}; print $0}' dir/file1.txt > dir/file2.txt

Thanks a lot and have a nice Day!