How to make second file print down the whole first file?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to make second file print down the whole first file?
# 1  
Old 08-30-2019
How to make second file print down the whole first file?

Using Python

I have 2 text files (big files over 1gb) that opens side by side on the same line in terminal, but I want the file on the right to print down the other file while the file on the left is stationary or displayed all at once. I want to print text file 2 through all of text file 1.
Code:
from itertools import izip

   with open("textfile1") as textfile1, open("textfile2") as textfile2: 
   for x, y in izip(textfile1, textfile2):
    x = x.strip()
    y = y.strip()
    print("{0}{0}".format(x, y))


What it does now:

Code:
paste -d ' ' a b   

1  a                        
2  b                       
3  c                       
4  d                       
5  e                      
6                               
7                               
8                                 
9

Desired output:
Code:
1  ↓                          
2  a                       
3  b                       
4  c                       
5  d                       
6  e                       
7                               
8                               
9                               

1                               
2                               
3  ↓                          
4  a                      
5  b                       
6  c                       
7  d                       
8  e                       
9

Re-looping
Code:
                 
1  b                       
2  c                       
3  d                       
4  e                             
5                               
6                               
7  ↓                          
8  List is about to loop        
9  a

Moderator's Comments:
Mod Comment
Please, use code tags as required by rules.

Last edited by Peasant; 08-30-2019 at 02:38 PM.. Reason: Code tags
# 2  
Old 08-30-2019
I don't understand what you're trying to do.

If your input files are over a 1Gb, which we might assume means that there are millions of lines in each file, are you saying that you want to produce quadrillions of lines of output? Why in the world would you want to do that?
# 3  
Old 08-30-2019
Quote:
Originally Posted by Don Cragun
I don't understand what you're trying to do.

If your input files are over a 1Gb, which we might assume means that there are millions of lines in each file, are you saying that you want to produce quadrillions of lines of output? Why in the world would you want to do that?

I'm not trying to go that route and produce many lines like that. Lets say I have a python script that could load and run a file over 1GB like the script I have at the top and I have another text file that's 1GB also. Is there a way I could pipe hex the python script to the text file and print the python script against the text file and get combinations but without producing quadrillions of lines. Using the text file as a place holder for lines.
# 4  
Old 08-30-2019
Quote:
Originally Posted by bigvito19
I'm not trying to go that route and produce many lines like that. Lets say I have a python script that could load and run a file over 1GB like the script I have at the top and I have another text file that's 1GB also. Is there a way I could pipe hex the python script to the text file and print the python script against the text file and get combinations but without producing quadrillions of lines. Using the text file as a place holder for lines.
You say you aren't trying to go that route, but that is exactly what your "desired output" and your "re-looping" show in post #1 in this thread.

I don't know what "pipe hex the python script to the text file" means.

I don't know what "print the python script against the text file" means.

By definition a text file contains a sequence of zero or more lines of text. I don't know what "Using the text file as a place holder for lines." means.

Please explain clearly in English what you are trying to do and show us (small) sample input files and the exact output you hope to produce.

Note that if you want all of the combinations of millions of lines (10**9) from one file with millions of lines (10**9) from another file you are talking about quadrillions of combinations (10**9 * 10**9 = 10**18) (i.e., quadrillions of lines of output).
# 5  
Old 08-30-2019
Quote:
Originally Posted by Don Cragun
You say you aren't trying to go that route, but that is exactly what your "desired output" and your "re-looping" show in post #1 in this thread.

I don't know what "pipe hex the python script to the text file" means.

I don't know what "print the python script against the text file" means.

By definition a text file contains a sequence of zero or more lines of text. I don't know what "Using the text file as a place holder for lines." means.

Please explain clearly in English what you are trying to do and show us (small) sample input files and the exact output you hope to produce.

Note that if you want all of the combinations of millions of lines (10**9) from one file with millions of lines (10**9) from another file you are talking about quadrillions of combinations (10**9 * 10**9 = 10**18) (i.e., quadrillions of lines of output).


Image


This is the pipe hex example

example.py | file1./another program will be here

Example of output

example.py | file1
generating | aaa
lines | bbb
↓ | ccc
printing against | ddd
the text file | eee

Last edited by bigvito19; 08-30-2019 at 06:57 PM..
# 6  
Old 08-30-2019
I only see the two files printed side by side. I do not see any other combinations of either input file in your desired output.

I'm obviously not contributing anything here, so I'll be quiet and hope someone else can figure out what you're trying to do and will be able to help you. I apologize for any confusion I have caused.
# 7  
Old 08-31-2019
My updated example

Image

Bash: 100: command not found

IOError: [Errno 32] Broken pipe

Last edited by bigvito19; 08-31-2019 at 06:02 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make a copy of a file when someone tries to modify the file

I wish to take a backup of the file when someone tries to modify a file say /tmp/test.txt using vi, vim, cat, copy, mv commands. I'm aware of inotify which will notify me of any changes to the file however, I wish to make a backup before and not after the changes are made to the file. I... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. UNIX for Beginners Questions & Answers

How to make paste -d second file print down while looping?

]I would like to make the second file label 'b' print down the first file label 'a', like shifting down the file creating new lines I want it to print all the way down until the first line of the second file hit the last line of the first file. Would I have to put this into a file itself or could I... (24 Replies)
Discussion started by: bigvito19
24 Replies

3. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

4. Shell Programming and Scripting

How to make multiple small file out of a single file?

Hi, I have a file that consist of around six million line, now the task is to divide this file into 12 small file so that each file would have half a million lines in it. Thanks. (3 Replies)
Discussion started by: mukulverma2408
3 Replies

5. Shell Programming and Scripting

make the name of file and fetch few things from log file

Hello All, I am working on a script where I need to fetch the value from a log file and log file creates with different name but few thing are common DEV_INFOMGT161_MULTI_PTC_BLD01.Stage_All_to_stp2perf1.042312114644.log STP_12_02_01_00_RC01.Stage_stp-domain_to_stp2perf2.042312041739.log ... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

6. Shell Programming and Scripting

how to make my own file as a running log file in bash

Hi, I have written a small script from that iam appending the output to a file.If multiple users invoke the same script or if i invoke the same script n number of times (using &), the output file(ZZ/OUT) contains messup information. #!/bin/bash # echo "Hello" >> /tmp/ZZ/OUT sleep 10 echo... (4 Replies)
Discussion started by: blrguest
4 Replies

7. Shell Programming and Scripting

How to call a batch file in Make file?

Hii I wanna call a batch file from a make file. Doesn't work , what is the procedure to do this.? Any idea thanks:eek: (2 Replies)
Discussion started by: krishnampkkm
2 Replies

8. Programming

makeutility: how to get the make-file name inside of the make-file?

How I can get the current make-file name in a make-file So, if I run make with specified file:make -f target.mak is it possible to have the 'target' inside of the that 'target.mak' from the file name? (2 Replies)
Discussion started by: alex_5161
2 Replies

9. Shell Programming and Scripting

Paste content of a file to another file and make it as columned

Pls help me on this. I have to 2 files like shown below: File 1 TAIJM AXPKIM BEMGW File 2 PXMPA JYGE IMJP What i want to do is to paste both file to a new file on thir format: File 3 TAIJM PXMPA AXPKIM JYGE BEMGW IMJP I tried cat and print, but it doesn't work. Cn... (6 Replies)
Discussion started by: kingpeejay
6 Replies

10. Shell Programming and Scripting

compare two files and make 1st file same as 2nd file

I am trying to compare two file and make changes where ever its different. for example: Contents of file1 IP=192.165.89.11 NM=255.255.0.0 GW=192.165.89.1 Contents of file2 IP=192.165.89.11 NM=255.255.255.255 GW=192.165.89.1 NOTE HERE THAT NM IS DIFFERENT So i want the changes... (6 Replies)
Discussion started by: pradeepreddy
6 Replies
Login or Register to Ask a Question