This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can I Extract PMID only for a query in a text file while searching it on NCBI pubmed?

Hello all.

I have search "mycobacterium avium complex" at NCBI pubmed and I got 5963 results. I just want to extract only the PMID of all these 5963 papers in a file, can be a text file.

Is it is possible or not, if possible please help me in doing the same.

Thanks.

sequence literature extraction alignment next-gen

2 answers

You can use Entrezdirect to do this:

$ esearch -db pubmed -query "mycobacterium avium complex" | efetch -db pubmed -format native | grep PMID > PMID_file

will get you

PMID: 27401987  [Indexed for MEDLINE]
PMID: 27393550  [Indexed for MEDLINE]
PMID: 27389727  [Indexed for MEDLINE]
PMID: 27383726  [Indexed for MEDLINE]
PMID: 27383107  [Indexed for MEDLINE]
PMID: 27380997  [Indexed for MEDLINE]
PMID: 27375559
PMID: 27373718  [Indexed for MEDLINE]
PMID: 27368989  [Indexed for MEDLINE]
PMID: 27350276  [Indexed for MEDLINE]
PMID: 27339212
PMID: 27336739
PMID: 27335625
PMID: 27335623
PMID: 27332519  [Indexed for MEDLINE]

If you only need the actual numbers you can do the following:

$ esearch -db pubmed -query "mycobacterium avium complex" | efetch -db pubmed -format native | grep PMID | awk -F " " '{print $2}' > PMID_numbers

I currently see 6201 papers.

thanks for helping me.

but I'm getting this error "WebEnv value not found in fetch input"

enter image description hereIf you save the result set as a file PMID list is an option (see image).

Screenshot of file save options

Log in to answer this question.