I have written a very simple bash script to help me migrate from dev to staging. What it does is it deletes all files in staging, copies the files over from dev to stage.
However, the config.inc.php file needs to have the first instance of ‘dev’ to be changed to ‘stage’, and no other instance changed.
Second, everytime I run it (I run the script from the dev directory), i’d like it to write a log back in the dev directory which will append the date/time stamp that I ran the staging bash script into this log.
Thanks.
This will change only the first appearance of ‘dev’ to ‘stage’
Be aware that it changes ‘devel’ into ‘stageel’. This version behaves just like you want, only a ‘dev’ is searched, not a ‘devel’ (in fact,
s/\<dev\>/stage/as the substitution expression should work, but it does not seem to work as expected? I’ll be glad if anyone with more sed-fu can explain. )For logging:
Added by Jonathan Leffler
sedcommand can still changedeveltostagelif the line contains, for example, ‘move devel code from /some/dev/location to /some/stage/location‘.sedcommand will map eachdevfound between the first line containingdevand the second such line. This matters if there’s more than one matching line, whereas the original ‘0,/dev/‘ (or amended ‘0,/\<dev\>/‘) only matches the first line as requested.'s/\<dev\>/stage/'doesn’t work is not asedissue but a shell issue. Use single quotes and you’d be almost OK. With double quotes, the back-slash less-than sequence appears tosedas just less-than.'\''‘. (The first quote terminates the single quote string; the backslash quote is a single quote; the last quote restarts the single quote string.)-i‘ option is a GNU extension tosed; it is a legimate part of the answer since the question is tagged Linux, where GNUsedis used; be aware if you need to move to a platform such as Solaris, AIX, HP-UX.seddoes not support extended regular expressions as standard; you have to explicitly enable them in GNU sed with the ‘-r‘ option.In my estimation, assuming overwrite is desirable, the command should be: