I have a data file say file1.txt, I want to match a pattern ("best-fit point:" or "best-fit") then print the last column of that line.
File1.txt
best-fit point: 0.0000 0.0000 0.0000 x coordinate 0.0000
best-fit point: -0.4330 -0.2500 0.0884 x coordinate 0.5078
best-fit point: 0.8660 0.5000 -0.1768 x coordinate 2.0310
best-fit point: -0.4330 0.2500 0.1768 x coordinate 3.4003
best-fit point: 0.8660 1.0000 -0.0884 x coordinate 4.9236
best-fit point: 0.4330 0.7500 0.0000 x coordinate 5.4313
best-fit point: 0.8660 -0.5000 -0.3536 x coordinate 6.8006
best-fit point: 0.0000 0.0000 0.2652 x coordinate 7.9766
best-fit point: 1.2990 0.7500 0.0000 x coordinate 9.4998
best-fit point: 0.8660 0.5000 0.0884 x coordinate 10.0076
best-fit point: 1.2990 -0.7500 -0.2652 x coordinate 11.3769
best-fit point: 0.8660 -1.0000 -0.1768 x coordinate 11.8846
best-fit point: 0.0000 0.0000 -0.5303 x coordinate 13.2539
Output
0.0000
0.5078
2.0310
3.4003
4.9236
5.4313
6.8006
7.9766
9.4998
10.0076
11.3769
11.8846
13.2539
My Solution and its problem
awk '/best-fit point:/{i==0 ; i++; print "K"i"="$8}' file-1.txt
This awk command is successfully working if there is no negative data in any column. Is there any other way to print the last column after the pattern match?
Thanks in advance!