This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to check if a word is present in a column of a .ped file

Hello everyone, I have a mydata.ped file, made up of 10215 rows (individuals) that looks like this:

1  MAL-005  0 0  1 1  3 3  4 4
2  MAL-006  0 0  3 3  1 1  4 4
3  MAL-007  1 1  0 0  1 3  4 4
4  MAL-008  1 1  0 1  1 3  3 4

Now, on bash, I need to check if the word "MAL-007" is present in the second column of mydata.ped file, and if yes, I want a script that prints "yes". Can anyone help me? Thank you.

ped bash
sed -n  '/MAL-007/ s/\tMAL-007\t/\tYes\t/p' test.txt | cut -f2

another awk solution:

awk '{ gsub("MAL-007","yes",$2);if ($2=="yes") print $2}' test.txt
awk '{ ($2 == "MAL-007")? $2="yes": $2="";if ($2=="yes") print $2}' test.txt

2 answers

cat my.ped | cut -f 2 | grep -q "MAL-007"
if [ $? -eq 0 ]
then
   echo "yes"
fi

with a little awk you will get there:

awk '{ if ($2 == "MAL-007") print "yes"}' <your .ped file>

It gives me this message: awk: program limit exceeded: maximum number of fields size=32767

strange. What is the exact command you're executing?

Log in to answer this question.