我有一个文件,我需要使用
shell脚本通过键查找值.文件看起来像:
HereIsAKey This is the value
我该怎么做呢?
MyVar=Get HereIsAKey
然后MyVar应该等于“这是值”.密钥没有空格,值应该是密钥之后的空白.
解决方法
如果HereIsAKey在您的文件中是唯一的,请尝试使用grep:
myVar=$(grep -Po "(?<=^HereIsAKey ).*" file)
我有一个文件,我需要使用
shell脚本通过键查找值.文件看起来像:
HereIsAKey This is the value
我该怎么做呢?
MyVar=Get HereIsAKey
然后MyVar应该等于“这是值”.密钥没有空格,值应该是密钥之后的空白.
如果HereIsAKey在您的文件中是唯一的,请尝试使用grep:
myVar=$(grep -Po "(?<=^HereIsAKey ).*" file)