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.
I can get it to do the first one, but not the 2nd and so on.
@druuna There's only one part of what he said that could refer to more matches from 0 to 1 and 2 and so on but that part still could also refer to just more matches of the two lines that he said. Putting that question aside there are two more statements that can tell that he was just referring to the two lines:
Quote:
Originally Posted by gdavis2287
I have a file with the following in it:
Quote:
Originally Posted by gdavis2287
I need to add "-nolisten tcp" to both of these lines
Referring to those statements which do you think has the higher probability, does he refer to 0..inf or just matches of the two lines?
@konsolebox: I'm not trying to make assumptions when it comes to questions asked, but most people tend to give small examples instead of full relevant examples, so sometimes you do need to make an assumption.
The fact that the example only holds 2 lines and that the OP talks about "... the first one, but not the 2nd and so on" contradict each other. The only safe assumption I can make at this point is that there are probably more then the 2 lines shown in the file that needs to be changed and that there could also be other, none-relevant, lines present in that file.
For me the higher probability is that the OP posted a small part of the file(s) s/he needs to change and my answer takes that into account.
Lets wait until the OP comes on line again and see what s/he really wanted/needed.
I should have said this is the Xservers file and that might have helped. In this file you can have any number of lines that start X on any given terminal. What is really boils down to is I want to add "-nolisten tcp" to any line that has /usr/X11R6/bin/X I guess. That should address the "and so on"...:N could be 0, 1, 2, 3, 4...
All lines should be changed that have /usr/X11R6/bin/X in it, so I would prefer to just ignore the :N portion of the file if possible because who knows what :N will be...most of the time there will only be one entry in this file, but we all know it's possible to have more.
I should also add if the line already has "-nolisten tcp" I don't want to append it again
So if the file looks like this below, I only need to add it to the one that does not have it.
:0 local /usr/X11R6/bin/X -nolisten tcp
:1 local /usr/X11R6/bin/X
I'm working on testing the solutions people have put in and will update this later today...
Thanks for all the replies.
Last edited by gdavis2287; 08-16-2010 at 08:00 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.