ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Thanks a lot for the reply druuna,
but the methods u said is not working... and it is not showing any error also...(but that option is not changing thats all) and if i use without -i it is printing the contents of the file and exiting.... now what to do.. ????
What do you mean "why it is like this"? Why in xinet.d tabs are used? Because they want it to be nicely formatted with slightly different parameter name length and without efforts. Why sed doesn't count ' ' as any whitespace? Because maybe you need just space. Why '[ \t]' works? Because  means 'one of contained single characters' and '\t' means tab.
thanks raskin....ya i should have been more specific... what i mean to say was " do i need to count all the spaces every time i need to change the option..???" if say some has intended in other way then " is there a way to skip those spaces and change the options.. say if it is like this in file...
" disable = no" and while using sed, should i have to take care of these spaces ?? or else how can i make "programmer friendly " i.e even though if i do not consider spaces it has to work ???
cp /etc/xinetd.d /etc/xinetd.d.000
sed -ri 's,^([ \t]*disable[ \t]*=[ \t]*)no,\1yes,' /etc/xinetd.d
I have done 5 things here:
Backed up the target file, just in case.
Used '(', ')', & '\1' to define a sub-expression in the match portion of the regex & then insert it in the replacement portion -- not only saves typing & mistakes, but preserves the formatting.
Used the "-r" option to avoid escaping those parentheses.
Put the 2 options together, but when using "-i" be careful to make it "-ri", not "-ir" -- that would make 'r' the back up file suffix.
Used ',' for the regex delimiter to make it easier to read. It's a little known, or at least rarely used, fact that even in Perl the '/' is NOT the mandatory delimiter. It can be anything you like -- sed uses the 1st character after the command (here, "s") as the delimiter. Pick whatever you find pleasing & easy to parse visually. for me, that's the comma in most cases.
sed is 1 of those basic commands w/ a lot of depth & power, & it pays to read the man page to know what it can do for you.
Thanks for the reply archtoad6,
still i am in confusion.. say (in the file the indentation is like this..) if there are 10 spaces before disable and 2 spaces after "disable" and 3 spaces after "=" sign and then "no"... now if i want to replace this by "yes" do i need to take care of these spaces in "sed" command. ??? cant i do simply like this.. sed -i -e 's/^disable = no/disable = yes/' /etc/xinetd.d/telne