The question is maybe trivial but I can't get it to work. I just want to merge 2 particular files present in multiple specific folders into a new single file again in each specific folder.
cat */folder_*/*/file.a */folder_*/*/file.b > */folder_*/*/file.c
but it does not work 'cause
-bash: */folder_*/*/file.c: No such file or directory
So I thought maybe for some reason cat
can't create files (though it does), so I tried
touch */folder_*/*/file.c; cat */folder_*/*/file.a */folder_*/*/file.b > */folder_*/*/file.c
but again it does not work with cat
or even touch
.
You can't use globbing for a destination file. You must fully specify the filename. It has nothing to do with cat
specifically.
Maybe you want something like this;
for a in */folder_*/*/file.a; do
# maybe continue if b missing
cat "$a" "${a%.a}.b" >"${a%.a}.c"
done
Wildcards and redirections are processed by the shell; cat
has no concept of wildcards, nor does it know where you are sending its output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With