-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_value.py
33 lines (23 loc) · 984 Bytes
/
extract_value.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0
def extract(file, detect_str, str1, str2):
#file_name = r'578_cpu_report'
file_name = file
with open(file_name, 'r') as fp:
# read all lines using readline()
lines = fp.readlines()
for row in lines:
# find() method returns -1 if the value is not found,
# if found it returns index of the first occurrence of the substring
if row.find(detect_str) != -1:
# getting index of substrings
idx1 = row.index(str1)
idx2 = row.index(str2)
# print(idx1)
# print(idx2)
res = ''
# getting elements in between
for idx in range(idx1 + len(str1), idx2):
res = res + row[idx]
# print("The extracted string : " + res)
return res