I have a file ontology.txt that looks like this
adipose.tissue subclass_of connective.tissue BTO connective.tissue part_of whole.body BTO adrenal.gland subclass_of endocrine.gland BTO endocrine.gland subclass_of gland BTO gland part_of whole.body BTO adrenal.gland subclass_of viscus BTO viscus part_of whole.body BTO bone subclass_of connective.tissue BTO connective.tissue part_of whole.body BTO bone part_of skeletal.system BTO skeletal.system part_of whole.body BTO bone.marrow part_of skeletal.system BTO brain part_of head old head part_of whole.body BTO brain part_of central.nervous.system BTO central.nervous.system part_of nervous.system BTO nervous.system part_of whole.body BTO heart part_of cardiovascular.system old cardiovascular.system part_of whole.body BTO kidney subclass_of excretory.gland old excretory.gland subclass_of gland old kidney subclass_of viscus old kidney part_of urinary.tract old urinary.tract subclass_of viscus old kidney part_of urinary.system old urinary.system part_of urogenital.system old urogenital.system part_of whole.body old liver subclass_of viscus old liver subclass_of digestive.gland old digestive.gland subclass_of endocrine.gland BTO I'm trying to write a script that will look at the fourth column, and if it has the word old in it, it won't write that line to the new file. Actually, file-writing isn't what I want to do. I want to do further operations on it. But for now, I'm doing this file-writing thing just to see if the script is fetching the right lines.
The problem is, my script ends up writing all the lines to the new file
#!/bin/bash while IFS= read -r line do t4=`echo "$line" | cut -f4` #echo "$t4" if [[ "$t4" != "old" ]] then echo "$line" >> ont22.txt else echo "NO" #t1=`echo "$line" | cut -f1` #t2=`echo "$line" | cut -f3` fi done < ontology.txt I have literally no clue what could possibly be going wrong with this simple chunk of code. So I'd really appreciate it if someone could point it out.
Note: If you copy over my ontology.txt block above. You should put it into another file (e.g. ont1.txt), and run this line to replace the consecutive spaces with a tab
cat ont1.txt | sed 's/ \+/\t/g' > ontology.txt Edit: As requrested by @Cyrus, here's the output to head -n 1 ontology.txt | hexdump -C
00000000 61 64 69 70 6f 73 65 2e 74 69 73 73 75 65 09 73 |adipose.tissue.s| 00000010 75 62 63 6c 61 73 73 5f 6f 66 09 63 6f 6e 6e 65 |ubclass_of.conne| 00000020 63 74 69 76 65 2e 74 69 73 73 75 65 09 42 54 4f |ctive.tissue.BTO| 00000030 0d 0a |..| 00000032
dos2unix ontology.txt.head -n 1 ontology.txt | hexdump -Cto your question.awk -F '\t' '$4!="old"' ontology.txt?