i have 2 text files. 1 text file "numbers.txt". contains 10 digit phone numbers, 1 on each line. second file "users" contains data several accounts. want find info on accounts listed in numbers.txt
so, each number in numbers.txt search users file said number. if found return line of text , following line of text (or return text until next empty line work).
numbers.txt looks like:
1234567021 1234566792
users file looks like:
1234567021@host.com user-password == "secret" framed-ip-address = 192.168.1.100,
result i'm looking for:
1234567021 1234567021@host.com user-password == "secret" framed-ip-address = 192.168.1.100
i'm stuck / stumped how approach it. have far:
#!/usr/bin/env python import os # load numbers text file if os.path.isfile("numbers.txt"): print "loaded numbers" #### open file, if exists numbers = open('numbers.txt', 'r') else: print "error: unable read numbers.txt" quit() # load user data file if os.path.isfile("users.txt"): print "loaded user data" #### open file, if exists users_data = open('users.txt', 'r') else: print "error: unable read users_data" quit() #### search if any(str(users_data) in s s in numbers): line in numbers: if number in line: #### produce sanitized list of output output = line.split(' ') #print output[0] print output # need next line users_data # after each match #### close numbers file , quit numbers.close() users_data.close() quit()
read numbers set
with open('numbers.txt') f: numbers = {line.strip() line in f if line.strip()}
look @ first ten characters of each line in users.txt
. if string in numbers
, save 2 lines container (dict
)
result = dict() open('users.txt') f: line in f: key = line[:10] if key in numbers: value = line + f.next() result[key] = value