How to create a makefile to sort all the .txt files in the directory and save it as .sorted using makefile?
Solution 1:
(*.sorted)
is just looking for a file with that literal name. You probably want
all: $(patsubst %.txt,%.sorted,$(wildcard *.txt))
%.sorted: %.txt
sort $< -o $@
The $(wildcard *.txt)
generates a list of all your text files, and the $(patsubst ...)
generates a parallel list with .sorted
instead of .txt
.
(Notice that Stack Overflow renders tabs as spaces, so you will not be able to simply copy/paste this code from the rendered page.)
For just make
to do what you want, you need the target to be the first one in the Makefile
. Perhaps see also Makefile: all vs default targets