How to write a .sh script to read configuration file and write into .txt file
Okay so i'm very new to this (my first shell script actually) and having a hard time knowing even where to start..
so my task is to create a shell script that will read a configuration file, find the specific info I need from the config file and write it into a .txt file. Here's an example of the config file: file name = config.properties Code:
#Tue Oct 18 16:23:06 GMT-05:00 2011 What I need the script to do is go through the file and find info i need and paste into .txt file. This is an example of what I would like the .txt file to look like after i run the script on this config file: Code:
environment=${devel:env} Help please! Thank you all in advanced! |
look into the grep command particularly the -f argument.
|
Quote:
Okay, so read the man page for that and still confused. Can you show me an example that I can work off of? Will I need to have a separate grep -f command for every variable I would like copied? |
Quote:
a text file is NOT defined by *.txt a text file can be , well, anything .csv ,.obj ,.sh ," no dot anything " config files ARE text files std input > std output this sounds a bit like homework so an example of output Code:
man grep > ~/man-grep-text you can open that test file with any text editor ( kate, Gedit,Emacs,vi,nano) |
Quote:
But anyways, this seems like a simple task to do, I understand the concept and what needs to be done just not exactly sure how to write the script so it will work properly. Is there a way that I can write a script and insert lets say a list of configurations that need to be copied from the file? Where I can manually change the specific content it should look for.. So i can lets say ask for these: devel.ldapConfig.url devel.ldapPool.timeBetweenEvictionRunsMillis devel.ldapPool.initialPoolSize and into my specified file it will copy this: devel.ldapConfig.url=ldap\://155.165.192.12\:389 devel.ldapPool.timeBetweenEvictionRunsMillis=1234556 devel.ldapPool.initialPoolSize=2 |
Quote:
In other words, if the line was "environment=${prod:env}" would you look for lines: Code:
prod.ldapConfig.url=ldap\://155.165.192.12\:389 Also consider using sed. Especially if the order is important and you can't rely on it in the source config file. If "devel" is not a constant, extract the value first, and then use in another grep or sed command to filter out the lines you want: Code:
ENVTYPE=$(sed '/environment=\${/s/.*{\(.*\):env}/\1/') Code:
sed -n -f filterrules.sed config.properties >config-seg.txt |
This is a possible soln
Code:
# 1. given cfg file as specced |
Quote:
Exactly what I was looking for! Thank you all for you help. chrism01 you rock! :) |
No worries :)
As you're new to shell scripting, I highly recommend these links http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ sed & awk tools (& other stuff) http://www.grymoire.com/Unix/ |
All times are GMT -5. The time now is 11:45 AM. |