I have a script called get_numbers.sh, which I want to use to extract data from .pdf files labelled sequentially by date, using pdfgrep.
Let me simplify my problem to what I believe are its essentials:
The .pdfs are named file-07-01.pdf, file-07-02.pdf, ..., file-07-31.pdf, where the numbers correspond to the month and day of the data in the file.
I can enter a shell command like
pdfgrep -i "Total Number:" file-07-{01..12}.pdf
and I get exactly what I want, the appropriate text from each file for the dates 07-01 to 07-12.
I want to make a script for this, where all I have to do is enter the start and end dates as well as the month. This was my first go:
#!/usr/bin/bash
if [ "$#" -eq 3 ]
then
START_DAY=$1
END_DAY=$2
MONTH=$3
else
echo "INCORRECT USAGE:"
exit 1
fi
pdfgrep -i "Total Number:" file-$MONTH-{$START_DAY..$END_DAY}.pdf
But doing bash get_numbers.sh 01 12 07 gives me the error message
pdfgrep: Could not open file-07-{01..12}.pdf
Looking around, I've realized that you have to be careful when doing this, because the script will interpret file-$MONTH-{$START_DAY..$END_DAY}.pdf as a literal string rather than a glob. I've tried to modify this, by making this a variable, or putting double quotes around it, but it doesn't change the result. What am I missing?
seqrather than the accepted answer based oneval.seqlike one of the later answers/examples, becauseevalwas doing something funny with the search pattern. You learn something every day!for m in $(seq -w "$1" "$2"); do files+=("file-$3-$m.pdf"); donethenpdfgrep -i "Total Number:" "${files[@]}"pdfgrepinside the loop - this does seem to be noticeably faster. Thanks again!