I have multiple files which I want to concat with cat
.
Let's say
File1.txt
foo
File2.txt
bar
File3.txt
qux
I want to concat so that the final file looks like:
foo
bar
qux
Instead of this with usual cat File*.txt > finalfile.txt
foo
bar
qux
What's the right way to do it?
This works in Bash:
In contrast to answers with
>>
(append), the output of this command can be piped into other programs.Examples:
for f in File*.txt; do cat $f; echo; done > finalfile.txt
(for ... done) > finalfile.txt
(parens are optional)for ... done | less
(piping into less)for ... done | head -n -1
(this strips off the trailing blank line)