shell - 从文件中提取字符串并将其存储在变量中
问题描述
我有一个文件,其中包含以下行。
ARG VERSION="6.0.0" // Here 6.0.0 is the version and could be any number.
我需要提取此值 6.0.0 并将其存储为 shell 变量,以便稍后在构建中使用。
有没有办法做到这一点?
解决方案
sed -nE 's/ARG VERSION=\"(.*)\"/\1/p' <file_with_string>
可能工作。
在这种情况下,我们捕获双引号之间的内容,选择第一个捕获 group( \1
) 和 print( p
)
推荐阅读
- swift - 如何从表格视图中删除单元格
- ios - 将条形码字符串发送到 Swift 中的 API 端点
- r - 根据其他列和行有条件地计算一列中不同数量的项目
- javascript - 使用 AXIOS 将 Array 对象作为 POST 传递给 .NET Web API 时遇到问题
- python - 提取html的特定部分
- python - lambda 并应用于在数据框中搜索值
- javascript - 如何将 json 解析传递给带有必填字段的类型变量
- jenkins - Jenkins - WinRM 插件获取会话空错误
- google-cloud-platform - 如何获取有关谁触发了我们的 Cloud Scheduler 作业的用户信息 - Google Cloud
- visual-studio-code - jupyter 魔术命令在 vscode 上有效吗?