Joining multiple files into a single file in unix Joining multiple files into a single file in unix unix unix

Joining multiple files into a single file in unix


I want the new file to start at the beginning of a new line.

If this is what you want, cat is probably the command you want. You can insert a newline by either piping a blank echo:

cat plainFile.abc > combined.fileecho >> combined.filecat pdfFile.pdf >> combined.file

Or, a slightly less messy way, you can create a file with just a blank line using echo:

echo > blank_line

Then use this cat command:

cat plainFile.abc blank_line pdfFile.pdf > combined.file

EDIT

1) The pdf is not starting from a new line. 2) Also, the pdf is shown as damaged file in mainframe. Is CAT the correct way to combine multiple files of different type into single file ?

If you want to concatenate them, then yes, you use cat. If you want to combine many files together and then be able to separate them afterwards, you don't use cat because that's not what it's for. The binary pdf is going to be corrupted because you've concatenated it to the end of an ascii file. If you want to be able to separate the files later, follow infgeoax's advice and use tar.

cat doesn't do things that allow you to separate what you've concatenated together once you've done it. For example, you have 3 strings: "are", "a", "dyes". You concatenate them and you get "areadyes". Without any prior knowledge to what you started with, you can't separate them into 3 strings again. Is it "are", "a", "dyes"? Or "a", "read", "yes"? You can add spaces, or some other character for delimiting your strings but what if the string you've started with has one of those characters?

If you don't have tar on this mainframe, you'll have to think of something else. Maybe instead of using cat on the pdf file, use something like hexdump, od, or uuencode/uudecode to dump the binary file to ascii, then on the mainframe, rebuild the binary file.


Why not use tar.

tar cf outputfile plainfile.abc pdfFile.pdf

And on the mainframe, you can reverse the process

tar xf ouputfile