I've got quite a long script so far and can't really manage to get this one awk command to work. I've got this for-loop:
echo "$numberoflipids" # 1
for (( i=0 ; i<$numberoflipids ; i++ ))
do
echo "${nol[$i]}" # POPC
echo "$pr" # 5
awk -v lipid="${nol[$i]}" threshold="$pr" '$4~/lipid/&&$NF>threshold{print >"filec";next}{print > "tmp"}' filea && mv tmp fileb
## Also tried this:
# awk '$4~/"'${nol[$i]}'"/&&$NF>"'$pr'"{print >"patch_rmlipids.pdb";next}{print > "tmp"}' bilayer_CG_ordered.pdb && mv tmp patch.pdb
## And this works... (giving the exact values)
# awk '$4~/"POPC"/&&$NF>5{print >"patch_rmlipids.pdb";next}{print > "tmp"}' bilayer_CG_ordered.pdb && mv tmp patch.pdb
done
the third awk command works perfectly fine for me... it searches column 4 in my filea for POPC, copies the lines that exceed 5 in the last column to filec and copies the remaining lines to fileb.
I hope one of you finds the time to read the code and maybe give me some advice in which way I failed to give awk these variables.
PS: My files look like this:
ATOM 624 SC1 SER 288 54.730 23.870 56.950 1.00 0.00
ATOM 3199 NC3 POP 487 50.780 27.750 27.500 1.00 3.18
ATOM 3910 C2B POP 541 96.340 99.070 39.500 1.00 7.00
ATOM 4125 W PW 559 55.550 64.300 16.880 1.00 0.00
(Old post regarding the awk command: bash - check for word in specific column, check value in other column of this line, cut and paste the line to new text file )