How to input variable into pubmed -esearch function
0
0
Entering edit mode
4.7 years ago
nattzy94 ▴ 60

I am trying to automate routine pubmed searches for daily use. My goal is for the program to output the publications present on pubmed for that day e.g. to get all publications from Nature on 8 Mar 2020.

So far I have the following:

cd /Users/nattzy/Documents/journal_articles
mkdir "$(date +"%Y-%m-%d")"

journals=('nature' 'nature communications' 'lancet')

for i in "${journals[@]}"
do
  :
  date=$(date +"%Y/%m/%d")[EDAT]
  query="\"$i[jour] AND $date\""
  echo "$query"
  esearch -db pubmed -query "$query" | efetch -format abstract > ./$(date +"%Y-%m-%d")/"$i".txt
done

When I run the script, all I get are empty text files. However, if I input the same search query manually on the pubmed website, I will get results. For example, today's search for Lancet articles: Lancet[JOUR] AND 2020/3/8[EDAT] gives me 6 results.

Would be great if someone could help with my script. Or suggest if there is another way to achieve the same goal. Thank you!

bash pubmed • 1.3k views
ADD COMMENT
0
Entering edit mode

Drop the extra quotes in your query. Change query="\"$i[jour] AND $date\"" to query="$i[jour] AND $date".

ADD REPLY
0
Entering edit mode

Ah okay, it works now. Thanks a lot!

ADD REPLY

Login before adding your answer.

Traffic: 2537 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