首页 > 解决方案 > 从文件中提取字符串并将其存储在变量中

问题描述

我有一个文件,其中包含以下行。

ARG VERSION="6.0.0" // Here 6.0.0 is the version and could be any number.

我需要提取此值 6.0.0 并将其存储为 shell 变量,以便稍后在构建中使用。

有没有办法做到这一点?

标签: shellawksedtext-parsing

解决方案


sed -nE 's/ARG VERSION=\"(.*)\"/\1/p' <file_with_string>可能工作。

在这种情况下,我们捕获双引号之间的内容,选择第一个捕获 group( \1) 和 print( p)


推荐阅读