Sample script is shown below:
#!/bin/bash
sed -i~ 's/user1/user2/g' myfile.txt
It replaces user1 with user2 in myfile.txt
How can I change above script to get confirmation that the script found user1 & replaced it with user2?
Basically, if it doesn’t find user1, it should give an alert message on the command prompt.
Thanks!
An alternative to diffing after is to grep before:
The
-qmeans that grep runs quietly and returns success if found, so then and only then will it go on to do the replacement.