【问题标题】:Hello, trying to figure out how to extract just the file path from this text你好,试图弄清楚如何从这个文本中提取文件路径
【发布时间】:2020-09-15 03:58:17
【问题描述】:
[[vfile:/path/to/fountain/file.fountain|This is a plot point]]

我尝试了以下方法。它删除了前面的 vfile 部分,但留下了 pipe(|) 以及后面的内容。

sed -e 's/.*\[\[vfile:\(.*\)\|.*/\1/'

我想要的输出只是喷泉文件的文件路径。

【问题讨论】:

  • 没关系,我想我只是删除了管道之前的反冲(|)
  • 嗯,简单的cut 命令很好:echo $string | cut -d: -f2 | cut -d\| -f1

标签: bash sed scripting


【解决方案1】:

试试

 sed -E 's#.*:(.*)\|.*$#\1#'

演示:

$echo '[[vfile:/path/to/fountain/file.fountain|This is a plot point]]' |  sed -E 's#.*:(.*)\|.*$#\1#' 
/path/to/fountain/file.fountain

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-28
    • 2020-09-17
    • 2016-01-27
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 2023-03-15
    相关资源
    最近更新 更多