or you could do
perl -p -i.bkp -e 's/abc(.*)abc/def$1xyz/' $file
Main Topics
Browse All Topicsfile content
==========================
abc some other words abc
==========================
in the above mentioned line i have a string abc twice, i want to change the first occurence of abc with def and second occurence of abc with xyz
i used
perl -p -i.bkp -e s/abc/def/ $file --> this will replace all the occurence's of abc in a file
can any one help me in this
Thanks
Prakash
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
one solution assumes the occurrences are on the same line, one assumes they are on different lines
the original perl -p -i.bkp -e s/abc/def/ $file will replace all the occurence's of abc in a file when they are on different lines
on the other hand, the
file content
==========================
abc some other words abc
==========================
looks like they are on the same line
perl -p -i.bkp -e "s/abc/def/..s/abc/xyz/g"
or
perl -p -0777 -i.bkp -e 's/abc(.*)abc/def$1xyz/s'
would work in both cases
Business Accounts
Answer for Membership
by: ozoPosted on 2007-09-16 at 22:54:51ID: 19903065
perl -p -i.bkp -e "s/abc/def/..s/abc/xyz/" $file