tawbah7
06-17-2003, 04:20 AM
salaams,
i'm trying to write a post installation bash shell script to perfom all the dirty work of setting up my linux box from scratch.
basically it is supposed to create users, install packages, edit configuration files and start services etc.
one of the things i need to be able to do is edit config files on the fly, that is, let the shell script take care of editing with no human interaction.
i undestand that sed and awk can be used with pattern matching and substitution capabilities to extract certain text from files and reorganize it but as far as i know...the changes do not take effect to the original file
for example, let us say that post-installation i would like a shell script to automatically open the httpd.conf file and enable all user directories (by default the user dirs are disabled). i know how to use the sed regular expression syntax to manipulate data from input files but how do i save changes to the original files?
ok...well i thought of one way to do this but it doesn't seem like a good aproach
here's what i did:
first, this is my example file:
# cat test
# first:second
# one:two
then i did this:
# TEST=`sed 's/first/FIRST/' test
# printf "$TEST\n" > test
and now this is what the modified version of test looks like
# cat test
# FIRST:second
# one:two
so what i did above was tried to capitalze the word 'first' in the file called test, i saved the output of the sed command in the TEST shell variable and rerwote it back in to the test file...i had to append an ending '\n' character though since it was not present in the TEST shell variable, though it should have been.
is there even a better way of doing this altogether?
i'm trying to write a post installation bash shell script to perfom all the dirty work of setting up my linux box from scratch.
basically it is supposed to create users, install packages, edit configuration files and start services etc.
one of the things i need to be able to do is edit config files on the fly, that is, let the shell script take care of editing with no human interaction.
i undestand that sed and awk can be used with pattern matching and substitution capabilities to extract certain text from files and reorganize it but as far as i know...the changes do not take effect to the original file
for example, let us say that post-installation i would like a shell script to automatically open the httpd.conf file and enable all user directories (by default the user dirs are disabled). i know how to use the sed regular expression syntax to manipulate data from input files but how do i save changes to the original files?
ok...well i thought of one way to do this but it doesn't seem like a good aproach
here's what i did:
first, this is my example file:
# cat test
# first:second
# one:two
then i did this:
# TEST=`sed 's/first/FIRST/' test
# printf "$TEST\n" > test
and now this is what the modified version of test looks like
# cat test
# FIRST:second
# one:two
so what i did above was tried to capitalze the word 'first' in the file called test, i saved the output of the sed command in the TEST shell variable and rerwote it back in to the test file...i had to append an ending '\n' character though since it was not present in the TEST shell variable, though it should have been.
is there even a better way of doing this altogether?