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.
Read up on awk too, while you're at it, which is often the better tool to use when working with field-style input. It can be used here as well, although you have to move it through a temp file to save the changes.
Well, don't you think that's something you should've mentioned at the beginning, then? You're probably not using bash either, right?
It's generally a good idea to spell out the full context of your situation, so we can provide you with useful answers, without wasting effort on things you can't use.
In any case, what's wrong with working through a temp file, as in my awk example above? It's only a couple of extra lines.
Oh yeah, and saying "it does not work for me", in your perl question above isn't very useful either. HOW did it fail? What exact command(s) did you use, and what output or error messages did you get?
Last edited by David the H.; 06-30-2011 at 12:26 PM.
Reason: addendum
perl -piw -e 's/10.1.1.1/10.1.1.2/ if /\bprinta\b/' /etc/hosts. this will find the line contained exact matched key word and replace it the whatever you want to.
this perl one liner in my script will be generated by provided variables.
Well I do not have access to ksh at the moment, but it should not matter as you essentially are not using
anything ksh-centric, and it works just fine inside the script (as I would expect seeing the script is just a wrapper).
When you say it doesn't run correctly, what do you mean?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.