[SOLVED] Replace field value in Configuration File
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Hi, I'm pretty new to scripting and having some difficulties with a sed command on Solaris 10. I need to be able to select a user from a configuration file and change an AccessLevel parameter within that section (see below). I've created a script that allows me to select the user and also the correct value within that section, but I can't work out how to write the new value.
The configuration looks as below:
The script I'm using is as follows:
`sed -n "/$user/,/AccessLevel/p" config.ldif | grep -w AccessLevel | head -1 | sed 's/^.* //' | sed "s/$old_value/$new_value/" config.ldif > config.ldif.tmp
I can see why this doesn't work as the final sed command is working on the original copy of the configuration and not the pattern I want it to match.
Solaris 10 seems to use quite an old/limited version of sed and if I didn't use head -1 it was returning other lines starting with the same string which I'm assuming is because of what you mentioned below? I'll have a go at modifying that bit to return an exact match.
As can be seen the head -1 does nothing.
If you did use the 1023 to modify config.ldif, it would change every occurrence of 1023, not just User1's.
Another thing to be wary of is that matching Fred will also match Frederick unless you anchor the regex to the end of line with the $ metacharacter.
Apologies as I should have also mentioned that AccessLevel will appear beneath dn: but the number of lines below is unknown. So using the +2 option in the command wouldn't work unfortunately. The config was just an example of what I was trying to do.