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!
sedtouch a flag file if it does a successful substitution. As an optimization, only do it for the first match. If your input files are too large for the grep && sed and diff solutions, it might be worth piecing together a somewhat more complex sed script.