views:

301

answers:

1

This is one line of the input file:

FOO BAR 0.40 0.20 0.40 0.50 0.60 0.80 0.50 0.50 0.50 -43.00 100010101101110101000111010

And an awk command that checks a certain position if it's a "1" or "0" at column 13 Something like:

 awk -v values="${values}" '{if (substr($13,1,1)==1) printf values,$1,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13}' foo.txt > bar.txt

The values variable works, but i just want in the above example to check if the first bit if it is equal to "1".

EDIT

Ok, so i guess i wasn't very clear in my question. The "$13" in the substr method is in fact the bitstring. So this awk wants to pass all the lines in foo.txt that have a "1" at position "1" of the bitstring at column "$13". Hope this clarifies things.

EDIT 2

Ok, let me break it down real easy. The code above are examples, so the input line is one of MANY lines. So not all lines have a 1 at position 8. I've double checked to see if a certain position has both occurences, so that in any case i should get some output. Thing is that in all lines it doesn't find any "1"'s on the posistions that i choose, but when i say that it has to find a "0" then it returns me all lines.

A: 
$ cat file
FOO BAR 0.40 0.20 0.40 0.50 0.60 0.80 0.50 0.50 0.50 -43.00 100010101101110101000111010
FOO BAR 0.40 0.20 0.40 0.50 0.60 0.80 1.50 1.50 1.50 -42.00 100010111101110101000111010

$ awk 'substr($13,8,1)==1{ print "1->"$0 } substr($13,8,1)==0{ print "0->"$0 }' file
0->FOO BAR 0.40 0.20 0.40 0.50 0.60 0.80 0.50 0.50 0.50 -43.00 100010101101110101000111010
1->FOO BAR 0.40 0.20 0.40 0.50 0.60 0.80 1.50 1.50 1.50 -42.00 100010111101110101000111010
ghostdog74
Plz check the edit in the OP
lugte098
I want to be able to specify the position of the "1" or "0". Only the OP example used the first position.
lugte098
show a valid example of your input file, and describe more clearly using that input file. I can't understand your problem. your substring statement in OP is correct if you are trying to pull the 1st character of the 13th field. why does it not work for you? if you want the 8th position of $13, then do `substr($13,8,1)==1`
ghostdog74
i edited the OP. I am using this substr($13,8,1)==1, but it doesn't seem to work.
lugte098
what doesn't seem to work ? position 8 of $13 is a 0 right? that's why it doesn't work since you are checking against 1.
ghostdog74
check the OP, plz
lugte098
close enough...
lugte098