I have 2 big files over 4Gbs each. I'm looking for a way to print 1 file, then when that file finish printing another file proceeds to print beside it and merge the lines together. How would to cmd or code this?
from itertools import izip_longest
with open("file1") as textfile1, open("file2") as textfile2:
for x, y in izip_longest(textfile1, textfile2, fillvalue=""):
x = x.strip()
y = y.strip()
print("{0}{1}".format(x, y))
My example: The first file on the left is already finished printing, then the second files prints next.
It's really not clear.
If you want to view the two files side by side, then I recommend MidnightCommander (mc).
To print the files side by side, you can try
With paste, how could I print 1 file first then have another file print on the side of it, printing against file 1? I want the second file to print down file 1 side by side by on the same line.
If you want to print files side by side, you have to print them at the same time.
Like you python script in your post#1 does.
In the shell the "read" command automatically chops the leading end trailing space.
while read L1 <&3 && read L2 <&4; do
echo "$L1$L2"
done 3< file1 4< file2
You see that it reads a line from file1 into variable L1 and simultaneously a line from file2 into variable L2. (Using two descriptors/streams that are opened when the loop starts.)
The echo command prints L1 and L2 side by side.
You actually mean to output the first file to the printer and then to reposition the paper to the first line and print the second file on a line by line basis starting at the first free print position on the line then I think that you are asking for quite a lot.
I'm going to go with the earlier contributors to this thread and suggest that paste is your best option at the moment.
You don't say anything about the system, not too mention the printer. A 4Gb file given your example of 6 chars per line would run to roughly 8 Million pages, this is going to take some time to print. So repositioning all the pages in the right order and running through the printer would be quite a task not to mention somewhat time consuming.
It starts to get really complex if you want to print a file and then run the same paper through the printer a second time printing at potentially a different start position for each line.
How much time? I'm not worried about how much time it will take. I know it will take a some time to complete. I agree that paste will be the best option for the task. I'm using xubuntu 4.12 and CentOS-6.9-i386. So is it possible to do this task and how would I set up the cmd or bash file?
Your requirements seem to be changing with every post that you make, can you show us some of your data.
You originally wanted to print two files with the contents side by side, now you want to print the first file in it's entireity with the first line of the second file appended to the end of each line - is this correct?
No I been wanted to print the first file entirely and then print the second file side by side making new lines as comes down the first file. I made a few examples.
The the example that you gave seemed to want the first line of each file printed on the same line, followed by the second line from each file printed on the same line etc...
Whereas your latest request was for;
The first line of the second file appended to the end of every line from the first file, before people can assist you you need to understand what you want.
You need to show us what you've tried and show us why it doesn't work by giving us a look at the expected output.