あなたの要求は少しあいまいですが、ここに役立つアイデアがいくつかあります。
10 個のファイルのうち 1 個が
# static_part.dynamic_part_like_date.pdf
# SalesReport.20110416.pdf (YYYYMMDD)
また、SalesReport.pdf のみをセキュリティで保護されていないものとして変換したい場合は、シェル スクリプトを使用して要件を達成できます。
# 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
%.*
あなたは物事を変更する必要があることに気付くかもしれません
- 最後の '.' だけを削除するには (%.* を使用)、最後から削除します。および後のすべての文字 (右からストリップ)。
- フロントから (#*. を使用して) 静的部分だけを取り除き、動的部分を残します OR
- 先頭から削除 (##*. を使用) して、最後の '.' まですべてを削除します。文字。
コマンドラインで必要なものを理解するのは本当に簡単です。1 つのサンプル ファイル名で変数を設定します
myTestFileName=staticPart.dynamicPart.pdf
次に、echo を変数修飾子と組み合わせて使用し、結果を確認します。
echo ${myTestFileName##*.}
echo ${myTestFileName#*.}
echo ${myTestFileName##.*}
echo ${myTestFileName#.*}
echo ${myTestFileName%%.*}
等
また、変更された変数値をプレーンな文字列 (.pdf) と組み合わせる方法にも注目してください。unsecuredName=${file%%.*}.pdf
IHTH