Easiest way to cross-reference a CSV file with a text file for common strings

与世无争的帅哥 提交于 2019-12-02 07:25:52

I would use Python for this. To print the matching lines, you could do this:

import csv
with open("strings.csv") as csvfile: 
    reader = csv.reader(csvfile)
    searchstrings = {row[0] for row in reader}   # Construct a set of keywords
with open("text.txt") as txtfile:
    for number, line in enumerate(txtfile):
        for needle in searchstrings:
            if needle in line: 
                print("Line {0}: {1}".format(number, line.strip()))
                break   # only necessary if there are several matches per line
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!