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 8797175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:47:51+00:00 2026-06-13T23:47:51+00:00

I have a configuraton file that I am editing and on the first pass

  • 0

I have a configuraton file that I am editing and on the first pass the is correctly changed but on the next two lines sed returns the lines blank.

The lines to be edited are

word.word.word.database=dbase
word.word.word.username=someone
word.word.word.password=someone

The sed commands I am using are

cat config.file | \sed -e "s/database/$dbname/" > config.file.1

cat config.file.1 | \sed -e "s/username/$dbuser/" > config.file.2

cat config.file.2 | \sed -e "s/database/$password/" > config.file.3

 cp config.file.3 config.file

The end result is

word.word.word.database=dbname
word.word.word.username=
word.word.word.password=

Can’t figure out what is going wrong with this. Any help would be great.

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. Editorial Team
    Editorial Team
    2026-06-13T23:47:52+00:00Added an answer on June 13, 2026 at 11:47 pm

    $dbname , $dbuser and $password are begin treated like shell variables, hence the leading dollar signs. If you’re trying to incorporate shell vars, try:

     sed -i -e "s/database/$dbname/" -e "s/username/$dbuser/" -e "s/password/$password/" config.file
    

    Notice that I’ve added the -i flag to the above command. It enables in-place editing using GNU sed. Other types of sed require an extension to be set, like: -i.bak and this creates a back up file; in your case this would be: config.bak.

    If you’re just looking to get the full list of results, either drop the dollarsigns or use single quotes. For example:

    sed -i -e "s/database/dbname/" -e "s/username/dbuser/" -e "s/password/password/" config.file
    

    or

    sed -i -e 's/database/$dbname/' -e 's/username/$dbuser/' -e 's/password/$password/' config.file
    

    EDIT1:

    If I’ve completely mis-understood your question, try this:

    sed -i -e "s/\(.*database=\).*/\1dbname/" -e "s/\(.*username=\).*/\1dbuser/" -e "s/\(.*password=\).*/\1password/" config.file
    

    Results:

    word.word.word.database=dbname
    word.word.word.username=dbuser
    word.word.word.password=password
    

    EDIT2:

    If you have shell vars labelled $dbname , $dbuser and $password:

    sed -i -e "s/\(.*database=\).*/\1$dbname/" -e "s/\(.*username=\).*/\1$dbuser/" -e "s/\(.*password=\).*/\1$password/" config.file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a configuration file that I consider to be my base configuration. I'd
I have some configuration data in a config file that I read off disk
I have a small cgi script that fetches and validates a configuration file for
I have a jar file with resources (mainly configuration for caches, logging, etc) that
We have a configuration file that lists a series of regular expressions used to
I have a configuration file that i would like to update with classic asp.
I have a web application, that contains a configuration xml file for one of
I have a client that references two assemblies : a WCF service and DLL
I have some text configuration file that need to be read by my program.
What I have is a configuration file that looks like this: Item|Size|Directory|Data A|12|D_01|11/28/10 C|13|D_01|11/28/10

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.