Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 99153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:19:59+00:00 2026-05-11T00:19:59+00:00

I have written a very simple bash script to help me migrate from dev

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:20:00+00:00Added an answer on May 11, 2026 at 12:20 am

    This will change only the first appearance of ‘dev’ to ‘stage’

    sed -i '0,/dev/ s/dev/stage/' config.inc.php 

    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. )

    sed -i  '/\<dev\>/,/\<dev\>/ s/dev/stage/' config.inc.php 

    For logging:

    date >> /path/to/dev/run.log 

    Added by Jonathan Leffler

    • Assuming other issues are resolved (see below), the second sed command can still change devel to stagel if the line contains, for example, ‘move devel code from /some/dev/location to /some/stage/location‘.
    • Also, the second sed command will map each dev found between the first line containing dev and 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.
    • The reason 's/\<dev\>/stage/' doesn’t work is not a sed issue but a shell issue. Use single quotes and you’d be almost OK. With double quotes, the back-slash less-than sequence appears to sed as just less-than.
    • Rule of Thumb: use single quotes around any argument in a shell script containing regular expression material. Unlesss it is saturated with single quotes, replace each single quote in the regular expression with the sequence quote, backslash, quote, quote ‘'\''‘. (The first quote terminates the single quote string; the backslash quote is a single quote; the last quote restarts the single quote string.)
    • Note that the ‘-i‘ option is a GNU extension to sed; it is a legimate part of the answer since the question is tagged Linux, where GNU sed is used; be aware if you need to move to a platform such as Solaris, AIX, HP-UX.
    • Finally, sed does 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:

    sed -i -r '0,/\<dev\>/s/\<dev\>/stage/' config.inc.php 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 115k
  • Answers 115k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the database has the default collation settings then 'blah'… May 11, 2026 at 10:24 pm
  • Editorial Team
    Editorial Team added an answer You can use something like cglib for generating code on-the-fly May 11, 2026 at 10:24 pm
  • Editorial Team
    Editorial Team added an answer I'd just use Tie::File. use Tie::File; use File::Copy; copy $file,… May 11, 2026 at 10:24 pm

Related Questions

If I create classes, that are used at the moment only in a single
This is probably a really basic problem but I can't seem to find any
I have a very simple TCP server written in C. It runs indefinitely, waiting
I have written a simple brainfuck interpreter in MATLAB script language. It is fed

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.