Print a python script down a list in a text file without printing a lot combinations


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Print a python script down a list in a text file without printing a lot combinations
# 1  
Old 09-02-2019
Print a python script down a list in a text file without printing a lot combinations

In a python script I have 2 files printing side by side on the same line. I want to have 1 of the files to be already displayed at once while the other file print down the list in the file and it still will produce new lines. I want to do it like that to reduce printing a lot of lines and combinations.




Code:
    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))

This is what the script does now:

    aaaaaa 111111

    bbbbbb 222222

    cccccc 333333     Both lines move and still print
                      the same lines every time.
    dddddd 444444  

    eeeeee 555555

    gggggg 666666



What I desire the script to do: 

                 This file2 is
                 about to go 
                 through file1
                    111111    This will print first in the order of the file
      
                    222222    second
      
                    333333    third
      
                    444444    fourth
      
                    555555    fifth
      
                    666666    This will print last in the order of the file
                      ↓↓
           
     This file1
     is already
     loaded or
     displayed 
     at once
     not moving
     at all
     aaaaaa
      
     bbbbbb        As file2 goes down file1, each line
                   should hit every line creating a new
     cccccc        combination until the list has completely
                   went through.
     dddddd
      
     eeeeee
      
     gggggg
                      
                      file2 is done going
                      through file1
                       111111
      
                       222222
      
                       333333
      
                       444444
      
                       555555
      
                       666666

Code:
      111111 should hit aaaaaa first, 
      then when 111111 will hit bbbbbb,  
      222222 should be on aaaaaa, 
      then when 111111 hit cccccc, 
      2222222 should be on bbbbbb, 
      then 333333 should be on aaaaaa, then so on and so on. 
      The list should go down the other list in a trail line until completely.



Example of output

Code:
            Example of output or what I should see in terminal 

    aaaaaa       
             
    bbbbbb 666666
             
    cccccc 555555
             
    dddddd 444444
             
    eeeeee 333333   Each line is trailing down the list
             
    gggggg 222222  
    
           111111


Last edited by bigvito19; 09-02-2019 at 04:48 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Insert FF (feed form) in text file so that when printing the printer print on a new page accordingly

Hello. First happy new year to everybody. I have a script that generate a text file ( /tmp/part_list.txt for example ). This file can be edited using a kde graphical text editor like kate or kwrite The file can be printed out from command line or within the text editor using the print... (5 Replies)
Discussion started by: jcdole
5 Replies

3. Shell Programming and Scripting

Bash script - printing range of lines from text file

I'm working on a new exercise that calls for a script that will take in two arguments on the command line (representing the range of line numbers) and will subsequently print those lines from a a specified file. Command line would look like this: ./lines_script.bash 5 15 <file.txt. The script would... (8 Replies)
Discussion started by: ksmarine1980
8 Replies

4. Shell Programming and Scripting

Print combinations of alphabets in a sequence

Hi Friends, I have a series of alphabets like this AGCAA The values inside the square brace indicate that either of them can be present at that position. And those ones without a brace, means that they are the only ones that could be printed at that location. Now, I would like to know... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

5. Programming

Python: Check 2 text files for string and print contexts

I have 2 text files: cities.txt San Francisco Los Angeles Seattle Dallas master.txt Atlanta is chill and laid-back. I love Los Angeles. Coming to Dallas was the right choice. New York is so busy! San Francisco is fun. Moving to Boston soon! Go to Seattle in the summer. ... (0 Replies)
Discussion started by: pxalpine
0 Replies

6. UNIX for Dummies Questions & Answers

print multiple lines from text file based on pattern list

I have a text file with a list of items/patterns: ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig12238 ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig34624... (1 Reply)
Discussion started by: Oyster
1 Replies

7. Shell Programming and Scripting

Python: generateeuro-millions combinations

Hello All!! Long time since i haven't been here, but here is my new question. I love giving myself challenges. Here is the new one: in the european euro-million, you choose 5 from 50 numbers plus 2 from from 9 "stars" (9 numbers). So in fact, you have the possibility to have 76275360... (4 Replies)
Discussion started by: penguin-friend
4 Replies

8. Shell Programming and Scripting

awk -- print combinations for 2 cols

Dear all, could you please help me with awk please? I have such input: Input: a d b e c f The number of lines is unknown before reading the file. I need to print possible combination between the two columns like this: Output: a d b d c d a e b e c e a f (2 Replies)
Discussion started by: irrevocabile
2 Replies

9. Shell Programming and Scripting

Regarding about the printing script/python

Hello, I am not sure whether this is the right forum or not, if not sorry for that. I am trying to print text at desire column with python script. eg. in this sentence print >>AA_sql, "Hello"+ "World" I want to print "Hello" at column10 and "World" at column30, simple idea is to... (2 Replies)
Discussion started by: davidkhan
2 Replies

10. Shell Programming and Scripting

Printing all combinations : Awk

$ cat key.txt #ID1 Start 1|AA1 2|AA2 3|AA3 4|AA4 #ID1 Complete #ID2 Start 1|BB1 2|BB2 3|BB3 #ID2 Complete I was required this output: AA1|BB1 AA1|BB2 AA1|BB3 (7 Replies)
Discussion started by: jkl_jkl
7 Replies
Login or Register to Ask a Question