I have a one line code which I don't understand why it isn't working
I have a file with 18 columns. If lines of column 8 start with either G or C and lines of column 9 start with either A or T, and if lines of column 17 start with either G or C and lines of lines of column 18 start with either A or T, then I would like to print two new columns saying "@" and "@", as columns 19 and 20.
You can't just group so many conditions with && and || like that. I mean you can, but figuring out what it does is very hard. For instance, does if ((A && B || C && D )) mean "if (A and B) or (C and D)"? Or does it mean "if(A and (( B or C) and D)"`?
It comes down to operator precedence and I don't know how awk will do this off the top of my head. So just avoid such ambiguity and either group things with parentheses: if(( A || B) && (C || D))
Or use my version which uses character classes instead of all those ||
The following snippet is not working as expected:
$k{"foo"}=1;
$k{"bar"}=2;
if(not defined($k{"foo"}) && not defined($k{"bar"})){
print "Not defined\n";
}
else{
print "Defined"
}
Since both $k{"foo"} and $k{"bar"} are defined, the expected output is "Defined". Running the code, howeve...
@MaharshiChakravortee It would be much better to ask on the site. This room isn't very active so you're not likely to get an answer here and, more importantly, if you ask here then you don't help anyone. If you ask on the site instead, other people can benefit from the answers you get (and the site benefits from having more useful content).