How to grep keywords?

I have below text file only with one line:

vi test.txt

This is the first test from a1.loa1 a1v1, b2.lob2, "c3.loc3" c3b1, loc4 but not from mot3 and second test from a5.loa5

Below should be the output that i want:

a1.loa1
b2.lob2
c3.loc3
loc4
a5.loa5

alv1 and c3b1 should be ignore.

The rules would be like below:
1) anything before keyword "from" should be ignore
2) anything after keyword "but" should be ignore if any

so we narrow down to below seach:
"from a1.loa1 a1v1, b2.lob2, "c3.loc3" c3b1, loc4"
and
"from a5.loa5"
1) second sentence after keyword "from" should be ignore if any (example: a1v1 should be ignore)
2) first sentence after the comma would needed (example b2.lob2, c3.loc3 and loc4 are needed)
3) second sentence after the comma should be ignore (example c3b1)
4) any double quotes should be remove (example "c3.loc3" should be output as c3.loc3 - no double quotes)

should have the output as below:

a1.loa1
b2.lob2
c3.loc3
loc4
a5.loa5

I know that this is a bit tricky, but this is required from my application, I would indeed really appreciate if someone could help me on above.

Thanks

Hello,

Please use the code tags as per forum rules, also please let us know the input for same.

Thanks,
R. Singh

Hi,

This is my text file:

This is the first test from a1.loa1 a1v1, b2.lob2, "c3.loc3" c3b1, loc4 but not from mot3 and second test from a5.loa5

The output should look at below:

a1.loa1
b2.lob2
c3.loc3
loc4
a5.loa5

I don't have any input yet, as i not sure how to start, perhaps it should be using awk or sed and I would be thankful for anyone can help me with this.

Thanks

awk '{split($0, a, "from");
  for(i = 2; i <= length(a); i += 2)
    {split(a, b, "but");
    split(b[1], c, ", ");
    for(j = 1; j <= length(c); j++)
      {gsub("\"", X, c[j]);
      split(c[j], d, " ");
      print d[1]}}}' test.txt