How to print 1 file then when finished another file prints beside it?

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.

 
          df585a
          fd6330
          ab854a
          ede361
          aadc55
          e8d562
    a1d2d3
    f6ac4b
    73fd36
    c4e5a3
    f66a99
    0c11da


          df585a 
          fd6330 
          ab854a 
    a1d2d3ede361 
    f6ac4baadc55 
    73fd36e8d562 
    c4e5a3       
    f66a99       
    0c11da   


        
    a1d2d3df585a 
    f6ac4bfd6330 
    73fd36ab854a 
    c4e5a3ede361 
    f66a99aadc55 
    0c11dae8d562 

Please post the code you are currently running to "print" these files, because it is not clear what you are trying do accomplish.

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

paste file1 file2

I posted the code

--- Post updated at 09:14 PM ---

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.

How to print file1 first then print file2 beside it after file1 has finished printed?

Hi,

If by;

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.

Regards

Gull04

1 Like

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?

Hi,

Even if you use paste to setup one single file of approximately 8Gb and given your example of the required output, I would calculate the following.

Twelve Characters per line and Sixty Six lines per page, assuming printing on A4 paper using standard spacing would give the following ;

Pages in the file = (1024x1024x1024x8)/(66*12) = 10,845,000 Pages.

If you have a printer capable of 20 Pages Per Minute then 540,000 Minutes or 9,000 hours or 376 Days.

Post the output from below and we can take it from there.

#> LINES=`wc -l ${filename} | awk '{ print $1 }'`
#>echo ${LINES} / 66 | bc

As to the how to do it, well.

[root@fbakirpomd4 ~]# cat test_01.txt
abc
def
ghi
[root@fbakirpomd4 ~]# cat test_02.txt
123
456
789
[root@fbakirpomd4 ~]#
[root@fbakirpomd4 ~]# paste test_01.txt test_02.txt > test_03.txt
[root@fbakirpomd4 ~]# cat test_03.txt
abc     123
def     456
ghi     789
[root@fbakirpomd4 ~]# paste -d "" test_01.txt test_02.txt > test_04.txt
[root@fbakirpomd4 ~]# cat test_04.txt
abc123
def456
ghi789
[root@fbakirpomd4 ~]#

Regards

Gull04

1 Like

How would I be able to get line 123 to to match up with every line to the left ex.
abc123
def123
ghi123 and so on?

Hi,

What have you tried, can you post anything?

Regards

Gull04

I tried everything that's been posted, paste, cat, awk.

Hi,

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?

Gull04

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.

Hi,

Your original post wanted;

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.

Regards

Gull04

Moderator comments were removed during original forum migration.