how to replace string by other one in a file & without perl ?
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.
This is something that you do in sed or awk.
If each instance in contained on the same line, and the replacement won't make the line too long, then a single sed command can do it:
sed 's/the little bird/the little turtle that/g' file1.txt.
However, if the phrase may be split on two lines, you need to add more rules which build up two lines in a buffer and ignore \n characters.
The first edition of the O'Reily "Sed & Awk" book may be available on the web.
This is something that you do in sed or awk.
If each instance in contained on the same line, and the replacement won't make the line too long, then a single sed command can do it:
sed 's/the little bird/the little turtle that/g' file1.txt.
However, if the phrase may be split on two lines, you need to add more rules which build up two lines in a buffer and ignore \n characters.
The first edition of the O'Reily "Sed & Awk" book may be available on the web.
thank you very much ! Nothing than the best reply :-) ! Our bash
Then, now, hence, that s the beginning for me working with Awk.I liked yoru help ! I have a book with Awk and will study it.
==
(When I was googling I was really scared by these \//\\\\\\//////\\\\\\ and my trials didnt worked all the time )
If you find yourself doing this kind of operation often, you could write your own command to do it simply.
Quote:
Early versions of Unix also had a gres command (perform a substitution on all matching lines) but it was obsoleted by sed and abandoned. -- http://www.perlmonks.org/?node_id=501419
It's not difficult to do this once or twice with a sed or awk command, but for continual use it is convenient to do it from the command line. I wrote and improved the one I use in your proscribed language but clearly you could use anything that is appropriate for the task to achieve this:
Code:
gres "the little bird" "the little turtle" filename
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.