I am looking to monitor content changes within a file and when that content changes, produce a notification displaying the new text.
Details
Let us say the file (connection.txt) contained only the words
"You are connected to the internet".
However, when the computer disconnects from the internet, the contents of the file change to "You are now disconnected from the internet".
How would you monitor the contents of the file and, only when the contents change, display the new text in a desktop notification (I am using Manjaro).
To add to the problem, this file is updated every four seconds, often with exactly the same text.
My research
I have searched for solutions to this with no avail. I have found many examples of monitoring files and directories for event changes such as files created, modified or deleted, but nothing on real-time monitoring of text inside a file.
If this is possible, are there similar techniques for monitoring changes to the output of a command?


watchto catch the changes, anddiffto report what changed.