Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In a folder containing X files, I need to concatenate Y files (where X > Y) together into a single text file. I have the filenames (of Y files) that I need to concatenate.

Can anyone please help me out on how to concatenate these files?

share|improve this question
    
In what format do you have the Y files? –  forcefsck Feb 16 '12 at 19:54
    
@forcefsck: They are in text format as well –  darkie15 Feb 16 '12 at 20:03
add comment

2 Answers

You can use the cat command (see man cat for more information) to concatenate the text files.

If you want to create a new file

# cat [FILE1] [FILE2]... > new_file

or if you want to append to an existing file use it like this

# cat [FILE1] [FILE2]... >> file 
share|improve this answer
add comment

If the Y filenames are listed in a list file, a simple combination of xargs and cat is enough:

xargs cat <list >>concatenation_of_files

In the case you've been careful and you've listed files one per line (to avoid problems with spaces in filenames), then just add a -d delimiter option:

xargs -d'\n' cat <list >>concatenation_of_files

(This assumes concatenation_of_files is initially inexistent or empty).

share|improve this answer
    
Cool! Obvious but didn't see it. –  forcefsck Feb 17 '12 at 21:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.