bash - 正确使用带有变量的 printf
问题描述
我正在使用以下命令检索信息:
EXP=$(curl "https://www.ebi.ac.uk/ena/data/warehouse/filereport?accession=ERR146982&result=read_run&fields=study_accession" 2>/dev/null| tail -n 1)
DESC=$(curl "https://www.ebi.ac.uk/ena/data/view/${EXP}&display=xml" 2>/dev/null | grep "<DESCRIPTION>" | sed 's/ <DESCRIPTION>//g' | sed 's/<\/DESCRIPTION>//g')
printf "$line\t$DESC\n"
但是,我得到了错误printf: ')': invalid format character
和输出(此处缩短)ERR146988 Background: Observations that the airway microbiome is disturbed [...] Streptococcus being the most common genus (49.72
我如何正确地printf
与变量结合使用,这些变量基本上可以取所有可能的值,包括特殊字符?
期望的输出:
ERR2319455 The American Gut project is the largest crowdsourced citizen science project to date. Fecal, oral, skin, and other body site samples collected from thousands of participants represent the largest human microbiome cohort in existence. Detailed health and lifestyle and diet data associated with each sample is enabling us to deeply examine associations between the human microbiome and factors such as diet (from vegan to near carnivore and everything in between), season, amount of sleep, and disease states such as IBD, diabetes, or autism spectrum disorder-as well as many other factors not listed here. The American Gut project also encompasses the British Gut and Australian Gut projects, widening the cohort beyond North America. As the project continues to grow, we will be able to identify significant associations that would not be possible with smaller, geographically and health/disease status-limited cohorts.
解决方案
你要:
printf "$line\t%s\n" "${DESC}"
查看
help printf
顺便说一句,如果您安装了 xmllint,您可以使用 xpath 更好地获得描述:
curl "https://www.ebi.ac.uk/ena/data/view/${EXP}&display=xml" \
| xmllint --xpath '//DESCRIPTION/text()' -
推荐阅读
- c# - 如何使用 Mapsui 保存地图的一部分?
- wso2 - 当 SAP 使用 bapi 调用 WSO2 侦听器时,它不会等待答案
- node.js - Mongoose 过滤器基于带值的动态日期键
- oracle - 如果值列表不包含条目,则 Oracle 表单显示消息
- python - Django - 如何在多个表单上使用完全相同的 clean() 方法
- react-admin - 如何在更新前转换记录值?- 更新 API 需要与获取 API 不同的格式
- javascript - 如何通过javascript函数获取当前的webelement clientHeight和scrollHeight?
- c# - MS Graph API:获取通道消息
- c# - Visual Studio 目标框架未更改为 4.0
- kubernetes - 如何在 gcp 上复制 Kubernetes 工作负载?