我正在寻找从line变量生成的最后一行bash-4.1$ cat file1_dup.py
#!/usr/bin/python
with open("file1.txt") as f:
lines = f.readlines()
for line in lines:
if "!" in line:
line = line.split()[-1].strip()
print lineoutput i am getting is as follows ..
^{pr2}$
The result i wanted to be printed out is
-125.10584323Moreover, i got the hint from some goghling and getting the output
desired but that seems bit complicated to me at the point ..bash-4.1$ cat file2_dup.py
#!/usr/bin/python
def file_read_from_tail(fname,n):
with open(fname) as f:
f=f.read().splitlines()
lines=[x for x in f]
for i in range(len(lines)-n,len(lines)):
line = lines[i].split()[-1]
#line = line.split()[-1]
print line
file_read_from_tail('file1.txt',1)this yeilds teh desired as folows..bash-4.1$ ./file2_dup.py
-125.10584323