How to check if a word is present in a column of a .ped file
2
0
Entering edit mode
3.7 years ago
Nuthatch • 0

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 • 847 views
ADD COMMENT
0
Entering edit mode
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
ADD REPLY
2
Entering edit mode
3.7 years ago
cat my.ped | cut -f 2 | grep -q "MAL-007"
if [ $? -eq 0 ]
then
   echo "yes"
fi
ADD COMMENT
1
Entering edit mode
3.7 years ago

with a little awk you will get there:

awk '{ if ($2 == "MAL-007") print "yes"}' <your .ped file>
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2735 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6