ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.. ????
I looked at the files in /etc/xinetd.d and they contain some control character as ^I. We can verify this by opening the file with vi or vim and setting
Code:
:set list
this shows all the hidden characters. To strip out the ^I chars you can use sed in this way:
Code:
cat telnet | sed 's/^V^I/ /g' | sed 's/disable = no/disable = yes/'
Note that instead of literally write the ^V^I chars, you have to press Ctrl-V Ctrl-I in sequence. The line above will look like
Code:
cat telnet | sed 's/ / /g' | sed 's/disable = no/disable = yes/'
Edit: Just seen the last posts... sorry for redundancy!
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.