SED edits configuration file
Hi everybody,
I want to write a simple bash script that changes specific options from a configuration file (called conf_file). Conf_file format is somewhat similar to this: Code:
[session1] Code:
sed ' Could anyone tell me how to archive this? I prefer sed but any other methods also be welcome. |
I would grep for session first and then do something accordingly:
Code:
if [ `grep -c "[session1]"` -gt 0 ]; then |
Thanks CRC123.
That helps a lot. |
That's OK. I knew it. Thanks.
|
Moin,
some hints: Quote:
Code:
if grep -q "^\[session1\]" conf_file; then Code:
sed -r ' So I would prefer this code: Code:
if grep -q "^\[session1\]" conf_file; then |
Sed
hello everyone!
i need do drop the '/ptw' from a passwd file the users are added to directory user:x:557:503::/ptw/home/user:/bin/bash and i need to drop the '/ptw' from every user that i am adding wasn't able to accomplish the mission :( |
Try change the default home directory for useradd :
Code:
useradd -D -b /home A quick sed fix for the actual /etc/passwd file would be: Code:
sed -i 's#/ptw##' /etc/passwd |
Quote:
Your suggestions was great. I'm just new to bash scripting and both your suggestions was very useful to me. CRC123 gave me the idea and help me figure out the right solution with if else condition & command substitution. I relied on input & output redirections because they are consistent among Unix utilities. However, I'd be glad to learn more about sed & grep, thanks a lot for advices. |
All times are GMT -5. The time now is 04:21 PM. |