views:

57

answers:

3

I need to put the contents of all *.as files in some specified folder into one big file.

How can I do it in Linux shell?

+5  A: 

You mean cat *.as > onebigfile?

Grumdrig
Thx. Great. And how can I find files in all sub-folders?
Max
@Max: In zsh and Bash 4, `cat **/*.as > onebigfile` will do.
ephemient
+2  A: 

Not sure what you mean by compile but are you looking for tar?

Duck
Thx. But no. Just put contains ) Question is edited
Max
+4  A: 

If you need all files in all subdirectories, th most robust way to do this is:

rm onebigfile
find -name '*.as' -print0 | xargs -0 cat >> onebigfile

This:

  • deletes onebigfile
  • for each file found, appends it onto onebigfile (this is why we delete it in the previous step -- otherwise you could end up tacking onto some existing file.)

A less robust but simpler solution:

cat `find -name '*.as'` > onebigfile

(The latter version doesn't handle very large numbers of files or files with weird filenames so well.)

Laurence Gonsalves