I'd like to look for a specific set of strings in files with a specific file extension (here it's .textfile
) I have in the current folder. For this, I want to use make .
Beforehand, I convert all .pdf
files to .txt
files and rename their .txt
extension to .textfile
. The filename itself is to be left "unharmed" during the conversion. My code so far:
#Variables that save the filenames of all .pdf files
SOURCE=$(wildcard *.pdf)
OBJECT=$(SOURCE:.pdf=.textfile)
#The conversion target
textfile: $(OBJECT)
%.textfile: %.pdf
@pdftotext -f $(FROM_PAGE) $< $@
To look for a set of string within these files, I've added this to the code:
lookfor-%: $(OBJECT)
grep -H % $<
So calling make lookfor-Foo
would look for "Foo" in all .converted
files within the folder. If there is a match, it would print this to stdin:
file1.converted: Foo is here
file231.converted: here is Foo for you!
However, my Makefile doesn't do this. It always prints out the exact same 2 lines as a "match", even though the set of strings I'm looking for isn't even in any of these lines.
What am I doing wrong?
Your rule is incorrect. You need to use the pattern stem $*
as the search pattern for grep
...
lookfor-%: $(OBJECT)
grep -H '$*' $<
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.