Find the answer to your Linux question:
Results 1 to 3 of 3
Hello all, I'm working on a script to read a config file template, add the correct parameters based on user input, and output the config file. For example, the config ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    ctd
    ctd is offline
    Just Joined!
    Join Date
    Mar 2006
    Posts
    1

    read in template file, output to file


    Hello all, I'm working on a script to read a config file template, add the correct parameters based on user input, and output the config file.

    For example, the config file might look like:
    config.template
    Code:
    color=blue
    topping=$theTopping
    font=arial
    I want to read in the file, fill in the variables, and output the file to config.cfg

    I've tried the following:
    Code:
    thefile=`cat config.properties`
    echo thefile > config.cfg
    The problem is echo removes the linebreaks. I tried doing "echo -e thefile > config.cfg", and I put "\n" at the end of each line. This breaks the config up into different lines, but also puts a space at the beginning of each line after the first.

    Any suggestions on a working solution here? Thanks in advance.

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    I don't quite get what you're trying to do by:
    Code:
    thefile=`cat config.properties`
    echo thefile > config.cfg
    Why wouldn't you just do:
    Code:
    cp config.properties config.cfg
    Either way, I don't think I understand your question.

  3. #3
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    This seems to be a very popular approach:

    config.template:
    Code:
    color=blue
    topping=__theTopping__
    font=arial
    Then,

    Code:
    sed 's/__theTopping__/$VALUE/g' config.template [| sed ...] > config.cfg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •