您的要求有点模棱两可,但这里有一些想法可能会对您有所帮助。
假设您的 10 个文件中有 1 个是
# static_part.dynamic_part_like_date.pdf
# SalesReport.20110416.pdf (YYYYMMDD)
并且您只想将 SalesReport.pdf 转换为不安全的,您可以使用 shell 脚本来实现您的要求:
# make a file with the following contents,
# then make it executable with `chmod 755 pdfFixer.sh`
# the .../bin/bash has to be the first line the file.
$ cat pdfFixer.sh
#!/bin/bash
# call the script like $ pdfFixer.sh staticPart.*.pdf
# ( not '$' char in your command, that is the cmd-line prompt in this example,
# yours may look different )
# use a variable to hold the password you want to use
pw=foopass
for file in ${@} ; do
# %%.* strips off everything after the first '.' char
unsecuredName=${file%%.*}.pdf
#your example : pdftk secured.pdf input_pw foopass output unsecured.pdf
#converts to
pdftk ${file} input_pw ${foopass} output ${unsecuredName}.pdf
done
您可能会发现您需要将%.*
事物修改为
- 从末尾少剥离,(使用 %.*)只剥离最后一个 '.' 以及之后的所有字符(从右侧剥离)。
- 从前部(使用#*。)剥离到静态部分,留下动态部分或
- 从前面剥离(使用##*。)剥离所有内容,直到最后一个'。' 字符。
在 cmd-line 上弄清楚你需要什么真的会容易得多。使用 1 个示例文件名设置变量
myTestFileName=staticPart.dynamicPart.pdf
然后使用 echo 结合变量修饰符查看结果。
echo ${myTestFileName##*.}
echo ${myTestFileName#*.}
echo ${myTestFileName##.*}
echo ${myTestFileName#.*}
echo ${myTestFileName%%.*}
等等
另请注意我如何将修改后的变量值与纯字符串 (.pdf) 组合在一起,在unsecuredName=${file%%.*}.pdf
IHTH