bash - awk string inequality seemingly not working -
i have file want find lines column 3 , 4 differ. file looks like:
chr1:109506687 [t/g] bot top chr1:109506690 [t/g] bot top ...
the code use find these lines
awk '$3 != $4 {print $0}' cardio-metabo_chip_11395247_a.txt | shuf -n 10
problem using command results
rs3218791 [a/c] top top
where column 3 , 4 same.
when use conditional equality, namely ==
no output, tells me awk never considers 2 columns $3 , $4 equal, despite them being so.
ps. using :set list
in vim, file looks like:
chr1:109506687^i[t/g]^ibot^itop$ chr1:109506690^i[t/g]^ibot^itop$ ....
my awk version gnu awk 3.1.8, can't imagine having anything. should have been right in 1.0
what might wrong?
though can't reproduce issue (see below), think you're evaluating values numerically rather strings (all nonempty strings —even "0"
— numerically evaluate 1
). try this:
awk '$3 != $4 "" {print $0}' test
that concatenates $4
empty string , should therefore force desired string comparison.
i failed reproduce problem mawk 1.2 , gawk 4.0.1:
$ cat test chr1:109506687 [t/g] bot top chr1:109506690 [t/g] bot top rs3218791 [a/c] top top $ mawk '$3 != $4 {print $0}' test chr1:109506687 [t/g] bot top chr1:109506690 [t/g] bot top $ gawk '$3 != $4 {print $0}' test chr1:109506687 [t/g] bot top chr1:109506690 [t/g] bot top
the shuf
pipe shouldn't have it, nor should tabs vs spaces. (though safe, tried combinations in test.)
fun tip: {print $0}
implied if there's 1 clause no action. therefore, awk '$3 != $4'
same awk '$3 != $4 {print $0}'
... though sure you're not making code harder peers read.
Comments
Post a Comment