如何从电子表格中运行一组终端命令? [英] How do I run a set of Terminal commands from a spreadsheet?

查看:43
本文介绍了如何从电子表格中运行一组终端命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须运行一组Entrez Direct命令,以便基于电子表格中一列中的查询/搜索短语在Terminal中运行.如何基于电子表格自动重复运行终端命令?

I have to run a set of Entrez Direct commands to run in Terminal based on queries/search phrases in a column in a spreadsheet. How can I automatically run a terminal command repeatedly based off of a spreadsheet?

即,我有以下命令: esearch -db pubmed -query< query>"|efetch -format docsum |xtract -pattern文档摘要-element PubDate |切-c 1-4 |sort-uniq-count><目录>/<名称> .xls 还有一个电子表格,该电子表格在一列中包含< query> 的值,我还可以为文件输入值,以将结果发送至该文件.有138次迭代.我该如何自动化?

i.e., I have this command: esearch -db pubmed -query "<query>" | efetch -format docsum | xtract -pattern DocumentSummary -element PubDate | cut -c 1-4 | sort-uniq-count > <directory>/<name>.xls And a spreadsheet that contains values for <query> in a column, and I can also put in values for the file to send the results to. There are 138 iterations. How do I automate that?

推荐答案

我建议您将查询列保存在HOME目录中的文本文件中-可能使用复制粘贴并将其命名为 queries.txt .让我们想象一下它是这样的:

I would suggest you save the column of queries in text file in your HOME directory - probably using copy and paste and call it queries.txt. Let's imagine it looks like this:

Why do 24-hr gas stations have locks on their doors?
Why don't they make planes out of the same material as the indestructible black boxes?
If nothing sticks to Teflon, how do they stick it to the pan?

然后,我将以下内容另存为 runQueries 在您的HOME目录中:

Then, I would save the following as runQueries in your HOME directory:

#!/bin/bash
while read query; do
    echo Running query $query...
    esearch -db pubmed -query "$query" | efetch -format docsum | xtract -pattern DocumentSummary  ...
done < queries.txt

然后您可以在终端中运行一次以使脚本可执行:

Then you can run this once in Terminal to make the script executable:

chmod +x runQueries

然后您可以随意运行它多次,每次都使用它:

And then you can run it as many times as you like, using this each time:

./runQueries

示例输出

Running query Why do 24-hr gas stations have locks on their doors?...
esearch -db pubmed -query Why do 24-hr gas stations have locks on their doors? ...
Running query Why don't they make planes out of the same material as the indestructible black boxes?...
esearch -db pubmed -query Why don't they make planes out of the same material as the indestructible black boxes? ...
Running query If nothing sticks to Teflon, how do they stick it to the pan?...
esearch -db pubmed -query If nothing sticks to Teflon, how do they stick it to the pan? ...

这篇关于如何从电子表格中运行一组终端命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆