Solved

Appending a file to all specified files (*.cpp) recursively

Posted on 2004-04-20
6
269 Views
Last Modified: 2013-12-26
Hi,

I'd like to append some copy consturctor code

Foo::Foo(const Foo&r) // copy constructor
{
  copy ( r);
}
Foo& Foo::operator=(const Foo&r) // assgnment operator
{
   return copy ( r);
}
Foo& Foo::copy(const Foo&r)
{

    // assign each element to is corresponding value in our object

   return *this;
}

to the end of all my *.cpp files recursively.

I know manually, I can do

cat constructorfile.txt >> acppfile.cpp

but I'd like this to be automated.

Also, if you can, if the file that I just appended to can replace the instance of "Foo" with the filename (whihc is the same as the class... like MyClass.cpp), that would be most helpful.

Thanks!

-Edward

0
Comment
Question by:edwardt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:dtkerns
ID: 10872259
hmm looks like almost the same Q you just asked ...

if you have a directory tree use find

find . -type f -name \*.cpp | while read f
do
      awk 'BEGIN { f ='$f'; sub(".cpp$", "", f) }; { x = $0; gsub("Foo", f, x); print x }' constructorfile.txt >> $f
done

if they are all in 1 dir you could simplify the first line to:

for f in *.cpp
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 10872309

for i in *.cpp
do
   cat constructorfile.txt >> $i
done
0
 

Author Comment

by:edwardt
ID: 10872796
Hi,

I get the following error from the above code.

awk: cmd. line:1: BEGIN { f =./Args.cpp; sub(".cpp$", "", f) }; { x = $0; gsub("Foo", f, x); print x }
awk: cmd. line:1:            ^ parse error

Thanks.

-Edward
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:edwardt
ID: 10872841
Also, in my files, Foo is replace by ./filename, like


./Args::./Args(const ./Args&r) // copy constructor
{
  copy ( r);
}
./Args& ./Args::operator=(const ./Args&r) // assgnment operator
{
   return copy ( r);
}
./Args& ./Args::copy(const ./Args&r)
{
0
 
LVL 84

Expert Comment

by:ozo
ID: 10872932
find . -name \*.cpp -exec sh -c 'cat constructorfile.txt >> {}' \;
0
 
LVL 3

Accepted Solution

by:
dtkerns earned 500 total points
ID: 10879644
sorry, forgot find would add a ./

 try this


find . -type f -name \*.cpp | while read f
do
      awk 'BEGIN { f = "'$f'"; sub("^./", "", f); sub(".cpp$", "", f) }; { x = $0; gsub("Foo", f, x); print x }' constructorfile.txt >> $f
done
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question