How to join two different line specifically in text files?

how to merge multiple text files into one using cmd
combine multiple text files into one linux
batch file to combine multiple text files
combine multiple text files into one python
merge text files online
text file merge tool
merge multiple text files into one notepad++
combine multiple text files into one mac

Okay so i'm doing a text file question and 90 percent of the work is done. Although i'm printing two names at end of my code (both on different line) , i'm trying figure out how to print them on same line specifically like this :("Best students: " name + " " + name) (could have more than 2 names depending on the text in the text file). I have tried using end= " " to put them on same line and it had space in between them which worked fine.Until I had to put in specific text before it e.g print("Best Students :",name,end=" ") but that gave the following output :

Best Students : Michael Murphy Best Students : John Kelly

Expected output : Best Students : Michael Murphy, John Kelly Best mark: 89

Any tips or ideas that could help me out would be massively appreciated.

Thank you

file = "students.txt"
with open(file,"r") as f:
q = []
for i in f:
  i = i.split()
  number = i[0]
  q += (number,)
highest = max(q)


with open(file,"r") as f:
for i in f:
   i = i.split()
   number = i[0]
   if highest == number:
     name = " ".join(i[1:])
     print("Best Students :",name,end=" ")
# print("Best Mark:",highest)
# Best Students : Michael Murphy, John Kelly
# Best mark: 89

Stduents.txt
64 Mary Ryan
89 Michael Murphy
22 Pepe
78 Jenny Smith
57 Patrick James McMahon
89 John Kelly
22 Pepe
74 John C. Reilly

with open(file,"r") as f:
    names = ""
    for i in f:
       i = i.split()
       number = i[0]
       if highest == number:
         if names != "": names += ", "
         names += " ".join(i[1:])

print("Best Students :",names)

Modify the second part like this. I got this output

Best Students : Michael Murphy, John Kelly

6 Ways To Combine or Merge Multiple Text Files • Raymond.CC, It's especially useful for multiple logs or report files that could be spread across The other options are for stripping lines from the top of text files or adding line� To merge files line by line, you can use the paste command. By default, the corresponding lines of each file are separated with tabs. This command is the horizontal equivalent to the cat command, which prints the content of the two files vertically. Let’s say that we have two files, file_1 and file_2: We can merge these two files with the


You could have something like a flag, that we would only print the "Best student" in the first iteration.

file = "students.txt"
with open(file,"r") as f:
    q = []

    for i in f:
      i = i.split()
      number = i[0]
      q += (number,)
    highest = max(q)

studentFound = False
with open(file,"r") as f:
    for i in f:
        i = i.split()
        number = i[0]
        if highest == number:
            name = " ".join(i[1:])
            if(not studentFound):
                print("Best Students :",name,end=" ")
                studentFound = True
            else:
               print(",",name, end=" ")

    print("\nBest Mark:", highest)

Result

Best Students : Michael Murphy , John Kelly 
Best Mark: 89

Merging Multiple Text File Data, but Specific Lines to Another , I want a new file with all the important data. I've modified your batch file to produce the results you want. Use the following batch file (test.cmd): Formerly, there have been two predominant methods for joining text strings or cell references with strings in Excel. You could either join using the ‘&’ like this: In this case, we have joined the strings for “First” and “Last” names while placing a space (“ “) between the two using ‘&’.


Here is another answer:

file = "students.txt"

def get_highest_grade(input):
  with open(input, "r") as f:
    q = []
    for i in f:
        i = i.split()
        number = i[0]
        q += (number,)
    highest = max(q)
 return (highest)

def get_best_students(input, grade):
  with open(input,'r') as f:
    student_names = ''
    for i in f:
        i = i.split()
        number = i[0]
        if grade == number:
          if student_names != '': student_names += ', '
            student_names += ' '.join(i[1:])

    print('Best Students: {} with a grade point of {}.'.format(student_names, grade))  

    # output 
    Best Students: Michael Murphy, John Kelly with a grade point of 89.

highest = get_highest_grade(file)
get_best_students(file,highest)

Ways to Combine Two (or More) Text Files (Tips.Net), Windows provides a few different ways to do this, but some methods If you have a couple (or more) text files that you'd like to combine into tedious approach—especially if you have more than a couple of files Probably the simplest command-line approach to use in combining files is to use the Copy� “If the text up to the tab (\t) in a line is the same as the text (s) up to the tab (s) in the consecutive line (s), keep one occurrence of them and merge everything on the right hand sides of the tabs in the consecutive lines in question.” Another example (and by “TAB” I mean “\t”):


Combine lines into one line after specific line identifier, so I have a text file which contains the PDBID and cor Effectively search for positions in large bedgraph files using python (or other language if� First, enter into the input fields the lists to be combined. Then determine an eventual delimiter such as a hyphen and optionally a prefix and suffix for each line. Finally, simply click on the button labeled "Combine lists" to start the merging.


How To Merge Or Combine Multiple Files Into A Single File, How To Merge Or Combine Multiple Files Into A Single File If you have a This will help Duration: 4:07 Posted: 01-Oct-2018 For example, you may receive a CD that contains hundreds of text files, all in different directories, which you need to combine into one file for importing into Excel, etc. It’s also useful if you have network log files, server log files, or backup logs that you want to combine for purposes of data mining or data analysis.


Comparing and merging text files, The left and right File panes show the text contents and differences of the two files being compared. Notice that the two identical lines (containing a and c ) that are in different locations are marked with WinMerge menus, especially Merge. Diffchecker is a diff tool to compare text differences between two text files. Enter the contents of two files and click Find Difference. Try our desktop app.