446,276 Members | 1,951 Online Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

# how to get a specific words from the line

 P: 2 01JAN 06:49:30.439 WARNING - Entered Zone - Operator = 5, Body Part = Body, u = 75830967.07, v = 45233540.51, w = 0.00, delta = 3 From the above line how to print Entered zone and delta 3 Weeks Ago #1
3 Replies

 P: 94 If the input format is always constant, split the input data using "split". Expand|Select|Wrap|Line Numbers val = input('') l = val.split(',') m = l.split('=') n = l.split('=') x = m y = n print(x,y)   If there is a line feed code after delta = x, the following code works. Expand|Select|Wrap|Line Numbers f = open('filename') val = f.readline() while val:   l = val.split(',')   m = l.split('= ')   n = l.split('= ')   if ('Entered Zone' in m):       x = m       y = n       print(x,y)   val = f.readline() f.close   One space after "delta = x" followed by the next data. Expand|Select|Wrap|Line Numbers f = open('filename') val = f.readline() f.close val2 = val.replace(' ',',') word = val2.split(',') flg1 = False flg2 = False enterd = '' delta = '' i = 0 for elem in word:     if word[i] == 'Entered':         enterd = word[i+5]         flg1 = True     if flg1 == True and word[i] == 'delta':         delta = word[i+2]         flg2 = True     if flg1 and flg2:         print(enterd,delta)         flg1 = False         flg2 = False     i = i + 1   3 Weeks Ago #2

 P: 2 01JAN 06:49:30.439 WARNING - Entered Zone - Operator = 5, Body Part = Body, u = 75830967.07, v = 45233540.51, w = 0.00, delta = 3 01JAN 06:49:30.439 WARNING - Entered Zone - Operator = 5, Body Part = Body, u = 75830967.07, v = 45233540.51, w = 0.00, delta = 1 01JAN 06:49:30.439 WARNING - EXITED - Operator = 5, Body Part = Body, u = 75830967.07, v = 45233540.51, w = 0.00, delta = 2 01JAN 06:49:30.439 WARNING - Entered Zone - Operator = 5, Body Part = Body, u = 75830967.07, v = 45233540.51, w = 0.00, delta = 4 FILE consists of those lines i have get the lines containing Entered Zone and print the delta value 3 Weeks Ago #3

 P: 94 It look like there is no line break and there is no comma only after delta = x, so it is impossible with the previous post way. I think that After "delta = x", there will be an operation to separate by "split" with a space. 3 Weeks Ago #4 