On Mon, 16 Oct 2017 20:17:01 +0000, Pew, Curtis G
([email protected]) wrote about "Re: Where is the "z/OS V2R3
Elements and Features" web site?" (in
<[email protected]>):
> On Oct 16, 2017, at 1:39 PM, John McKown <[email protected]> wrote:
>>
[snip]
>> for i in *.pdf ; do pdfinfo "${i}" | ln -s "${i}" "$(awk '/^Title: / {print
>> substr($0,17);} | sed -r 's/ *.*? *//')" ; done
One can avoid the use of sed here. Moreover, we need to do more
manipulation of the generated filename for the symlink.
> Yes, please. I tried doing something like this once, but the PDF
> information sections are inconsistent or incomplete. Everything’s
> easier to manage when you have consistent, reliable metadata.
I have attached a shell script for zsh that might do what you want. It
is another "pretend text" attachment, so rename it with the ,txt suffix
removed. Also remember to "chmod +x" to make it executable.
Note also that this script will probably not work under Windows, even if
you have zsh installed as a shell. This is because it translates the
forward slashes IBM uses for z/OS, OS/390, OS/400, PL/I, etc. into
backward slashes, because UNIX filesystem drivers use the forward slash
as a directory separator.
I have released it under the Berkeley License, so it is fully open
source. Use at your own risk.
--
Regards,
Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[email protected] (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
#!/bin/zsh
# Script to scan PDF documents and add a symlink to those whose
# filename differs from their title fields.
# Copyright (C) 2017, David W Noon. All rights reserved.
# This code is released under the Berkeley License.
# Set default values.
DOC_DIR="."
let PRETEND_MODE=0
let VERBOSE_MODE=0
# Parse the command line.
while getopts 'pd:hv' OPTNAME
do
case "$OPTNAME" in
p)
let PRETEND_MODE=1
;;
d)
DOC_DIR="$OPTARG"
;;
h)
echo 'Usage:'
echo "\tPDF_symlinks.zsh -h -p -d <directory>"
echo ''
echo 'Where:'
echo "\t-p\t\tPretend mode."
echo "\t-d <directory>\tDirectory to scan. Default: current
directory."
echo "\t-h\t\tThis help text."
exit 0
;;
v)
let VERBOSE_MODE=1
;;
*)
echo "Invalid option $OPTNAME"
exit 12
esac
done
# Change directory if it's not current.
[[ "$DOC_DIR" == "." ]] || pushd "$DOC_DIR"
# Loop through all plain files ending in .pdf
for fn in *.pdf(N.)
do
# Extract the Title: field, massage to fit UNIX filename conventions.
sn=$(pdfinfo "${fn}" | gawk '/^Title:/ { s=$2; for(n=3;n<=NF;++n)
s=s"_"$n; gsub("/","\\",s); print s".pdf"; }')
if [[ -e "$sn" ]]; then
# Skip if name already exists.
[[ $VERBOSE_MODE -eq 1 ]] && echo "$sn already exists."
elif [[ "$sn" != "$fn" ]]; then
if [[ $PRETEND_MODE -eq 0 ]]; then
# Hit the tit!
ln -s "$fn" "$sn"
[[ $? -eq 0 && $VERBOSE_MODE -eq 1 ]] && echo "Symlink
$sn was created for $fn"
else
echo "Symlink $sn would be added to document $fn"
fi
fi
done
# Revert directory if we changed.
[[ "$DOC_DIR" == "." ]] || popd
exit 0
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN