Need a script to search and replace text in file using shell script
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.
Need a script to search and replace text in file using shell script
Hi Gurus,
I am very new to unix and currently learning.
I need a help. My concern is how to find a text in a file and replace the same with the another text value. The find and replace text values will be passed through the command propmpt something like:
The first step in scripting is figuring out exactly what you want done. Exactly.
Sure, you want to replace text, and you attempt to show how this would work on the command line. A good first step.
But do you want to specify the input and output file names in that command also? Or is that command just supposed to be a filter (in which case a simple, one-line sed command should work, with no script necessary)?
Or what?
If you don't know what a "filter" is, drop everything and google:
Code:
bash tutorial
because there is much you need to read before starting out.
Hope this helps.
Last edited by wjevans_7d1@yahoo.co; 06-20-2007 at 12:23 PM.
Well.... the wording is fine :} ... it just suggests that those aren't
your own words as it contradicts the statement that you're new to
scripting.
To be efficient with shell scripting you need to know the basic
command line tools. Read the man pages for grep, sed, and maybe
awk. Also scour this forum for those tools. You'll find tons
of useful examples.
And no, no one here will do your homework for you :}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.