小编Dwi*_*ija的帖子

从bash shell脚本中的整个字符串中提取路径

我需要从字符串中提取路径。我在另一篇文章中找到了示例,但缺少其他步骤。

我有一个字符串如下:

title="test test good dskgkdh hdfyr /rlsmodules/svnrepo/SOURCE/CBL/MQ/BASELINE/MQO000.CBL kdlkfg nsfgf trhrnrt"
cobsrc=$(awk '{match($0,/\/[^"]*/,a);print a[0]}' <<< $title)
echo $cobsrc
Run Code Online (Sandbox Code Playgroud)

输出是

/rlsmodules/svnrepo/SOURCE/CBL/MQ/BASELINE/MQO000.CBL kdlkfg nsfgf trhrnrt
Run Code Online (Sandbox Code Playgroud)

我只需要

/rlsmodules/svnrepo/SOURCE/CBL/MQ/BASELINE/MQO000.CBL
Run Code Online (Sandbox Code Playgroud)

需要什么修改?

关于类似查询的现有帖子: how to extract path from string in shell script

linux string bash shell

1
推荐指数
1
解决办法
1344
查看次数

标签 统计

bash ×1

linux ×1

shell ×1

string ×1