I have moved my classes from the global namespace to a specific namespace. I also changed the class names. I want to convert all source files that use these classes to a new format. I thought either a bash script, using a sed file on Cygwin, or running a perl script. I have problems with a bash script.
Here is the process I'm trying to execute:
- For each source file * .cpp and * .hpp, recursively:
- If the file contains the old class name, then convert the file.
- End for.
My problem in a bash script detects if the file contains the old class name. I was thinking of one grep expression for each class name:
for f in `find . -iname \*.[ch]pp`; do if [ grep "Field_Blob_Medium" $f -eq 0 || grep "Field_Boolean" ]; then sed -f conversion.sed $f fi done
The problem is that only one command can be in a bash if expression using this syntax:
if grep "Field_Unsigned_Short" $f;
so i cant make boolean OR from grep s.
I could execute a nested loop, but I don't know how to break out of the bash for loop:
OLD_CLASS_NAMES="Field_Blob_Medium Field_Boolean Field_Unsigned_Int" for f in `find . -iname \*.[ch]pp`; do for c_name in $OLD_CLASS_NAMES; do if grep $c_name $f then sed -f convert.sed $f
So, I am looking for suggestions on how to process each source file containing old class names and convert them to new ones. A preferred example is a Cygwin bash script, although a Perl script would also be acceptable. In addition, the script must backup the original source file before writing the converted content to the new file.
I am running Cygwin on Windows XP and Windows Vista.
c ++ bash perl sed cygwin
Thomas Matthews
source share