小编net*_*ric的帖子

用 sed 减少一个数字

我使用 提取了.txt文件中PDF 的元数据pdftk,现在我试图将BookmarkPageNumber每个书签的值减少一个整数。在.txt有这些行:

BookmarkBegin
BookmarkTitle: Preface
BookmarkLevel: 1
BookmarkPageNumber: 10
BookmarkBegin
BookmarkTitle: Author
... and so on
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用 sed 的替代命令来做到这一点,这是我目前所拥有的:

// $1 is the source .txt file; $2 is the decrement
// __ is a placeholder for the variable with the original value
cat $1 | sed "s/BookmarkPageNumber: [0-9]*/BookmarkPageNumber: `expr __ - $2`/" | cat > metadata.txt
Run Code Online (Sandbox Code Playgroud)

如何将原始值放入变量中,然后__在同一个 sed 表达式中用它替换 palceholder ?

sed regular-expression

3
推荐指数
2
解决办法
1741
查看次数

标签 统计

regular-expression ×1

sed ×1