I want to grep lines using this pattern file from a big file. In big file, the IDs are present in line two. The dummy format of big file is as follows:
Ensure that your files are delimited properly. You can convert all multiple whitespace to a single whitespace by running sed 's/ \+/ /g' on each file prior to using awk.
you can use the join command to get all lines which have a common field. Let t1.txt be your ID list and t2.txt your big file. (I just added some dummy values in column 3):
join -1 1 -2 2 -o 2.1,2.2,2.3 <(sort t1.txt) <(sort -k2,2 t2.txt )
fam1 1 A
fam2 10 A
fam3 1098 A
fam5 1099 G
FID IID some_more_columns
Since join needs sorted columns, you can produce temp-files with <(sort ) . The parameter -1 selects the field to join from file 1 -2 the field of file 2. With -oyou control the output: for each field x you want to have in your result, you need to add the 2.x to the list.
Hi Kevin,
I tired but nothing happened, than I tried by changing the {FS=" "} to
{FS="\t"}
but same result.Although worked well on test file.,,,,,,,,,,,,
Ensure that your files are delimited properly. You can convert all multiple whitespace to a single whitespace by running
sed 's/ \+/ /g'
on each file prior to usingawk
.Yes, in my file there is a special character ^M a classical problem dos2unix than your command worked for me, now its all ok......,,,,,,,!!!!!!!
Perfect,
Thanks,
Waqas,
Yes, I have encountered that problem before with ^M. dos2unix and unix2dos are useful tools to have.
Good luck
Which OS are you using?