您的要求有点含糊,但这里有一些想法可能会对您有所帮助。
假设1的10个文件是
# 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行。 设置有1个样本文件名
myTestFileName=staticPart.dynamicPart.pdf
一个变量,然后使用回声与可变改性剂组合以查看结果。
echo ${myTestFileName##*.}
echo ${myTestFileName#*.}
echo ${myTestFileName##.*}
echo ${myTestFileName#.*}
echo ${myTestFileName%%.*}
等
还要注意我如何IHTH
我很抱歉,我没有试过结合修改变量值与一个普通的字符串(.PDF),在
unsecuredName=${file%%.*}.pdf
你的解决方案另外我想要一行命令而不是shell脚本。感谢您的努力和答案。 – sgarg 2012-07-18 15:46:43