Old post, but I just ran into a very similar problem. After some experimenting, I found that you can do this with a single command:
kill $(ps aux | grep <process_name> | grep -v "grep" | cut -d " " -f2)
In OP's case, <process_name>
would be "gedit file.txt"
.