Computing.Net > Forums > Unix > Script for replacing multiple lines

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Script for replacing multiple lines

Reply to Message Icon

Name: Peggy
Date: November 4, 2002 at 04:08:13 Pacific
OS: solaris
CPU/Ram: not sure
Comment:

I am a beginner of shell scripts. I need help in writing a script for replacing duplicate of multiple lines in a list of files in a directory with some other lines.

For example, I have got some files in a dir named a, b, and c, and in each file there is a paragraph "etc etc etc... and etc" in it, and I want to replace the "etc etc etc... and etc" with "cte cte cte... and cte" for all files a, b, and c.

There is no need for input error checking and it is assumed that the list of files is known in advance and that there will be the exact same paragraph in every file in that list.

Many thanks in advance.

Peggy :)




Sponsored Link
Ads by Google

Response Number 1
Name: jimbo
Date: November 4, 2002 at 13:14:19 Pacific
Reply:

This will replace every line that has "etc etc etc" with "cte cte cte" in files a b & c:

cd /dir/with/files/
for i in `ls a b c` ; do
sed 's/etc etc etc/cte cte cte/g' $i > $i.$$
mv $i.$$ $i
done

-jim


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Script for replacing multiple lines

replacing the path definition www.computing.net/answers/unix/replacing-the-path-definition-/7094.html

Utility or script for renaming files on www.computing.net/answers/unix/utility-or-script-for-renaming-files-on-/2538.html

Equivalent perl script for sed www.computing.net/answers/unix/equivalent-perl-script-for-sed/5939.html