Here is a script using egrep that extracts the last word in each line:
egrep -o " [a-zA-Z'-]+[,:.!';?]*$" File.txt > Results.txt
If it is placed in a file with the requisite header:
#!/bin/bash
it works perfectly.
If on the other hand, one attempts it from the command line, one gets the following error:
-bash: !': event not found
The problem is the exclamation point in the regexp.
I have tried numerous ways to get it to work from the command line and failed: using single quotes, escaping the !, etc.
Nothing works.
Now, you may ask, if it works from a file, why insist on doing it from the command line? You're right. I shouldn't. And my research indicates that this problem is particularly annoying in bash and that people simply recommend using a different shell.
But can it be solved?
Thanks in advance...