1

I have several text files in a single folder, and I would like to merge only certain sequential files into one long one (where one file comes immediately after the next).

For example, I want to merge all files starting with test (so test1.txt, test2.txt, test3.txt, and so on) into one file named file.out, like so:

Stuff from test1
Stuff from test2
...
Stuff from testN

I tried cat * > file.out, but that merges everything, which is not what I want. How can I do this?

9
  • 2
    Possible duplicate of How can I merge files on a line by line basis? Jan 15, 2017 at 6:16
  • See linked duplicate. It's the job for paste command Jan 15, 2017 at 6:16
  • If all of your files have a prefix, you can use cat test* > out.file.
    – Kaz Wolfe
    Jan 15, 2017 at 6:17
  • @Serg That question seems to be about merging lines inside files, not about merging whole files. Jan 15, 2017 at 8:16
  • 1
    @JacobVlijm well, why don't we wait for OP to clarify. If it's not what they want , i.e. "merge" files, I'll remove my vote. Otherwise, it stays. As it is, the question can be closed for being unclear ,too. Jan 15, 2017 at 9:59

1 Answer 1

4
  • ways of using wildcards for cat
cat test[1-2].txt>out.txt  //matches any character in the set
cat test[!34].txt>out.txt  //matches any character not in the set
cat test?.txt>out.txt  //for a single character
cat test*>out.txt    // for any strings 
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .