How to compare the attributes start with $ in 2 functions and display match or mismatch

2024/11/23 15:59:10

My input file contain attributes

        if(match($OPTION_EnableDetails, "1") or match($OPTION_EnableDetails_juniper, "1")) {details($juniFileXferStatus,$juniFileXferTimeStamp,$juniFileXferIndex)}@ExtendedAttr = nvp_add(@ExtendedAttr, "juniFileXferStatus", $juniFileXferStatus, "juniFileXferTimeStamp", $juniFileXferTimeStamp, "juniFileXferIndex",$juniFileXferIndex)

I got lot of cases in my input file, How can i compare all instances start with $ in details and instances start with $ in nvp_add here?

Answer
import recaselines_index = []
cases = []
readlines = []def read(in_file):global casesglobal caselines_indexglobal readlineswith open(in_file, 'r') as file:for line in file.readlines():readlines.append(line.strip())for line in readlines:case_search = re.search("case\s\".+?\"\:\s", line)if case_search:caselines_index.append(readlines.index(line))#print caselines_indexcaselines_index_iter = iter(caselines_index)int_line_index = int(next(caselines_index_iter))int_next_index = int(next(caselines_index_iter))while True:try:case_text = ' '.join(readlines[int_line_index:int_next_index]).strip()case = [readlines[int_line_index].strip(), case_text]cases.append(case)int_line_index = int_next_indexint_next_index = int(next(caselines_index_iter))except StopIteration:case_text = ' '.join(readlines[int_line_index:len(readlines) - 1]).strip()case = [readlines[int_line_index].strip(), case_text]cases.append(case)breakdef work():MATCH = 1for case_list in cases:details = []nvp_add = []caseline = case_list[0].strip()nvp = re.findall("details\(.+?\)", case_list[1].strip())for item in nvp:result_list = re.findall("(\$.+?)[\,\)]", item)for result in result_list:if "$*" not in result:details.append(result)nvp = re.findall("nvp_add\(.+?\)", case_list[1].strip())for item in nvp:result_list = re.findall("(\$.+?)[\,\)]", item)for result in result_list:if "$*" not in result:nvp_add.append(result)missing_from_details, missing_from_nvp_add = [], []missing_from_details = [o for o in nvp_add if o not in set(details)]missing_from_nvp_add = [o for o in details if o not in set(nvp_add)]if missing_from_nvp_add or missing_from_details:MATCH = 0print caseline + "   LINE - " + str(readlines.index(caseline) + 1)for mismatch in missing_from_details:print "Missing from details:"print mismatchfor mismatch in missing_from_nvp_add:print "Missing from nvp_add:"print mismatchprint "\n"if MATCH == 1:print "MATCH"else:print "MISMATCHES"def main():in_file = "target1.txt"read(in_file)work()if __name__=="__main__":main()

If i understand correctly this is it

https://en.xdnf.cn/q/120722.html

Related Q&A

Python comparing elements in two lists

I have two lists:a - dictionary which contains keywords such as ["impeccable", "obvious", "fantastic", "evident"] as elements of the listb - sentences which cont…

Remove all keys that have values of N/A, -, or empty strings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 2…

Sorting algorithms more efficient than bubble sort [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 7 years ago.Improve…

How can I return the odd numbers of a list, using only recursion in Python? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

TypeError: int object is not iterable; Python 2.7

Here is my code:def numbers_in_lists(string):num = int(string)l = list(num)return lstring = 543987When i run it:print numbers_in_lists(string)I have the following error:l = list(num) TypeError: int obj…

Python: Are `hash` values for built-in numeric types, strings standardised?

I came to this question while pondering about the ordering of set, frozenset and dict. Python doesnt guarantee any ordering, and any ordering is coupled to the hash value at some level. But is the hash…

How to create a sample django project?

This doesnt work for me.$ python django-admin.py startproject myprojectI am running a ubuntu virtual m/c on my windows system. By default ubuntu 12.04 comes with python 2.7.3 so I am using that only I …

Why elif statement instead of if statement? [duplicate]

This question already has answers here:Difference between multiple ifs and elifs?(9 answers)Why we use if, else if instead of multiple if block if the body is a return statement(13 answers)Closed 7 ye…

How to understand regular expression with python?

Im new with python. Could anybody help me on how I can create a regular expression given a list of strings like this:test_string = "pero pero CC tan tan RGantigua antiguo AQ0FS0que que CS segn se…

How do I reverse words in a string with Python [duplicate]

This question already has answers here:Reversing words in a Python string (including punctuation)(5 answers)Closed last month.I am trying to reverse words of a string, but having difficulty, any assist…