Unix Programming - substitute pattern in files without using > nor mv

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > November 2004 > substitute pattern in files without using > nor mv





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author substitute pattern in files without using > nor mv
Laurent Schneider

2004-11-18, 7:47 am

Hi,
I read the following question posted a few months ago and I wanted to
suggest my answer ...

> De :jerrygarciuh
> Objet :newbie sed question
> View: Complete Thread (5 articles)
> Groupes de discussion :comp.unix.programmer
> Date :2004-05-29 21:41:00 PST
>
> <skip>
> I want to substitute all occurrences of foo with bar in all files named
> index.php recursively from my cwd.
>
> I tried this:
>
> ls -R| grep 'index.php' | sed 's/foo/bar/g'


Ok, there are answers with find . | while read do sed>tmp ; mv ...

My solution is ed

find . -name index.php -exec echo e {} '\ng/^/s/foo/bar/g\nw' \;; echo
q)|sed 's/ $//'|ed

:-)
Laurent
Nils O. Selåsdal

2004-11-18, 7:47 am

Laurent Schneider wrote:
> Hi,
> I read the following question posted a few months ago and I wanted to
> suggest my answer ...
>
>
>
>
> Ok, there are answers with find . | while read do sed>tmp ; mv ...
>
> My solution is ed
>
> find . -name index.php -exec echo e {} '\ng/^/s/foo/bar/g\nw' \;; echo
> q)|sed 's/ $//'|ed


find . -name index.php | xargs PERL -pi -e 's/foo/bar/g'
(and umpten variants thereof.)


--
Nils O. Selåsdal
www.utelsystems.com
Laurent Schneider

2004-11-19, 7:47 am

Excellent!
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com