How to merge text files with the same name from all subdirectories?

后端 未结 2 960
庸人自扰
庸人自扰 2021-01-29 02:23

I have several folders with files. Files can have the same names. I want to concatenate files into one of each name. Thanks in advance.

EDIT: I\'m sorry

2条回答
  •  攒了一身酷
    2021-01-29 02:55

    This is simple — you have go write each file to the same directory making sure you are appending. This does not guarantee any sort of order preference, so I assume it's irrelevant. You have not specified a language or whether this is for the shell, so I can't suggest an implementation (yet).

    This problem can be broken down into the following tasks. First you need a list of all the files. This can be done with ls -r or some PL specific way, if you are "programming". Then you need to figure out for each file path, where to write and that involves a regex or probably even a split on "/". Then you just want to read and append each file from A to B and that's it. Either do that with cat a >> b or with whatever language libraries you are using.

提交回复
热议问题