I have two text files:file #1: domain.txtcocacola.comairtel.compepsi.comfile #2: servers.txt192.0.53.42 , 4    # 4 domains already allocated on server 192.0.53.42192.53.1.2 , 1     # 1 domains already allocated on server 192.53.1.2192.36.155.21 , 2  # 2 domains already allocated on server  192.36.155.21I need to write a script, which will allocate each domain (one by one from top to bottom from domains.txt) to the server (to server.txt) which has the minimum load at a given instant (if there is a tie in minimum load then the the server is allocated with FCFS).Finally I want to write a script to do as above then create a new file with modifications named: allocation.txt.In the above example allocation.txt as a output will have (after execution of script):192.0.53.42 , 4192.53.1.2 , 3 , cocacola.com , airtel.com192.36.155.21 , 3 , pepsi.comI am a newbie to scripting, and would appreciate any help/guidance!What would be your basic approach to solving this problem? Can all this be accomplished by one script?
Scripting to domain allocation to server
text processing;scripting
The following python script should do what you want:#!/usr/bin/pythonserv=[]for l in open(servers.txt,r).xreadlines():  # for each server    s,n = l.split(,) # extract server name and load    n=int(n.split(#)[0].strip()) # ignore comments    serv.append([s.strip(),n]) # store server and its loadfor l in open(domain.txt,r).xreadlines(): # for each domain    m = serv.index(min(serv,key=lambda i:i[1])) # find server with lowest load    serv[m].append(l.strip()) # add the domain    serv[m][1]=serv[m][1]+1 # increase the loadalloc=open(allocation.txt,w)for l in serv:    print>>alloc,  , .join([l[0],str(l[1])] + l[2:]) # write output file