Shell 从文件中提取字符串并将其存储在变量中
我有一个文件,里面有下面一行Shell 从文件中提取字符串并将其存储在变量中,shell,awk,sed,text-parsing,Shell,Awk,Sed,Text Parsing,我有一个文件,里面有下面一行 ARG VERSION="6.0.0" // Here 6.0.0 is the version and could be any number. 我需要从6.0.0中提取这个值,并将其存储为shell变量,以便以后在构建中使用 有没有办法做到这一点?sed-nE的/ARG版本=\“(.*)\”/\1/p'可能会起作用 在本例中,我们捕获双引号之间的内容,选择第一个捕获组(\1)并打印(p)请尝试以下内容 awk 'match($0,/ARG VERSION="[
ARG VERSION="6.0.0" // Here 6.0.0 is the version and could be any number.
我需要从6.0.0中提取这个值,并将其存储为shell变量,以便以后在构建中使用
有没有办法做到这一点?
sed-nE的/ARG版本=\“(.*)\”/\1/p'
可能会起作用
在本例中,我们捕获双引号之间的内容,选择第一个捕获组(
\1
)并打印(p
)请尝试以下内容
awk 'match($0,/ARG VERSION="[^"]*/){print substr($0,RSTART+13,RLENGTH-13)}' Input_file
说明:添加上述内容的详细说明
awk ' ##Starting awk program from here.
match($0,/ARG VERSION="[^"]*/){ ##Using match function to match regex ARG VERSION=" till " here.
print substr($0,RSTART+13,RLENGTH-13) ##Printing sub-string of current line starting point is RSTART ending point is RLENGTH.
}
' Input_file ##Mentioning Input_file name here.
来源是一种选择吗?您可以将导出添加到每个配置中,只需对文件执行source。或者,export$(xargs