From: Parmenides on 11 Jul 2010 11:07 Hi, I have a old version linux directory tree, where all makefiles in the hierarchy are meant to be modified. Suppose that the current directory is at the top level of the tree, the first step I take is to use a command like find . -name Makefile | xargs sed 's/-mcpu/-march/g' It is obvious that the result of each makefile is not written into itself, but send to the stardard output. The point is that there is no way to specify the filename for each makefile for the sed. How to resolve the problem in a command line? Or, writting a script is necessary.
From: Chris F.A. Johnson on 11 Jul 2010 11:14 On 2010-07-11, Parmenides wrote: > > Hi, > > I have a old version linux directory tree, where all makefiles in > the hierarchy are meant to be modified. Suppose that the current > directory is at the top level of the tree, the first step I take > is to use a command like > find . -name Makefile | xargs sed 's/-mcpu/-march/g' > It is obvious that the result of each makefile is not written > into itself, but send to the stardard output. The point is that > there is no way to specify the filename for each makefile for the > sed. How to resolve the problem in a command line? Or, writting a > script is necessary. The GNU/Linux version of sed has an in-place option: find . -name Makefile | xargs sed -i.bak 's/-mcpu/-march/g' -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
From: Parmenides on 11 Jul 2010 11:31 Thanks a lot.
From: Robert Bonomi on 11 Jul 2010 13:52 In article <87k4p2oy45.fsf(a)gmail.com>, Parmenides <mobile.parmenides(a)gmail.com> wrote: > >Hi, > > I have a old version linux directory tree, where all makefiles in > the hierarchy are meant to be modified. Suppose that the current > directory is at the top level of the tree, the first step I take > is to use a command like > find . -name Makefile | xargs sed 's/-mcpu/-march/g' > It is obvious that the result of each makefile is not written > into itself, naturally!! sed never writes back to the original file. it is _stream_ editor, changing the stream of data that passes through it, *NOT* the original source. > but send to the stardard output. The point is that > there is no way to specify the filename for each makefile for the > sed. Of course there is. *IF* you "do it right". Consider, for example (untested): find . -name Makefile -exec csh -c "sed 's/-mcpu/-march/g' {} >new && mv new {}" \; > How to resolve the problem in a command line? Or, writting a > script is necessary. >
|
Pages: 1 Prev: Perl script permission question Next: Confounded by conditional expressions |