我使用 提取了.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 ?