I have a variables that needs to be modified so that minutes %M is added. I know the sed command and it is working as expected.
# cat mysed.txt
myfirstfile="comany$mydb`date +'%d-%b-%Y-%H'`.sql"
# sed -i 's/\%H/\%H-\%M/' mysed.txt
# cat mysed.txt
myfirstfile="company$mydb`date +'%d-%b-%Y-%H-%M'`.sql"
But if I run the same sed command again, it will add %M again as follows.
# sed -i 's/\%H/\%H-\%M/' mysed.txt
# cat mysed.txt
myfirstfile="company$mydb`date +'%d-%b-%Y-%H-%M-%M'`.sql"
I need a sed command that should add the minutes %M only once even if sed command is executed twice (by mistake)
This should work. This way it will only do the replacement if there is a quote mark next to the %H.