Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

how to concatenate files

by cpiety (Novice)
on Jan 20, 2005 at 02:04 UTC ( #423573=perlquestion: print w/ replies, xml ) Need Help??
cpiety has asked for the wisdom of the Perl Monks concerning the following question:

Hello from snowy MD.
Could someone show me a perl script to concatenate a long list of files into one large file?
Thank you for any wisdom.

charles

Comment on how to concatenate files
Re: how to concatenate files
by BUU (Prior) on Jan 20, 2005 at 02:10 UTC
    perl -pe1
      To elaborate on BUU's solution:
      perl -pe1 file1 file2 file3 ... > newfile

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

      thanks for the help. I have over a thousand files to concatenate together so I was hoping to do this in a loop. I created a file containing all the file names that I want to concatenate....hmm?
Re: how to concatenate files
by Errto (Vicar) on Jan 20, 2005 at 02:12 UTC
    If that's really all you need to do, and if you're on Unix, I would just do
    cat file1 file2 ... filen > big_file
    Or in Perl, do it with the following zero-line program typed from your shell prompt.
    perl -pne '' file1 file2 ... filen > big_file
    See perlrun for details.
      perl -pne '' file1 file2 ... filen > big_file
      Unless I'm missing something, the p flag is mutually inclusive of the n flag. That is to say that the n is redundant.

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        That could well be. Frankly, I'd gotten kind of used to typing it the other way so I didn't think to check.
Re: how to concatenate files
by data64 (Chaplain) on Jan 20, 2005 at 03:48 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://423573]
Approved by Errto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-07-30 18:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (239 votes), past polls