Friday, January 9, 2009

Refactoring my c++ code using bash

Renaming variable names within code
find . \( -name "*.h" -or -name "*.cpp" \) | xargs grep -i ActionResource -l | sort | uniq | xargs sed -i 's/ActionResource/Actuator/g'

and similarly for actionResource, ACTIONRESOURCE, ACTION_RESOURCE

find . | grep -v ".svn" | xargs grep -l TemporalInterval | xargs sed -i 's/TemporalInterval/TimeInterval/g' <-- this is for CMakeLists.

Renaming files
find . \( -name "*.h" -or -name "*.cpp" \) | sed 's/\(.*\)ActionResource\(.*\)$/mv "&" "\1Actuator\2"/'| grep ^mv | sh

Deleting ! files from svn
svn stat | grep ! | cut -f 3- -d " " | xargs svn del

No comments: