I have a working solution from an earlier question I asked for finding csv files in a source directory (/foo/source), chopping off the first 233 lines using tail, and saving that to a file in a different directory (/foo/dest):
find /foo/source -name "*.csv" | xargs -I '{}' sh -c 'tail -n +232 {} > /foo/dest/$(basename {})'
This works great when run as-is in bash.
My problem is the exact same command in a Makefile target fails:
copyfiles:
find /foo/source -name "*.csv" | xargs -I '{}' sh -c 'tail -n +232 {} > /foo/dest/$(basename {})'
make copyfiles
sh: /foo/dest//foo.source/somecsv.csv: No such file or directory
It seems that the basename command is no longer working when in Make, as it is just using the whole path + filename of the source file when saving.
Why is this happening, and is there a way around this? Is there a simpler way to achieve what I'm doing? I need to search a folder for csv files, tail, then save into a different location.
Thanks!