Thursday, November 29, 2007

Selective text replacement in a file on Unix

Select parts of a file for changing by naming a range of lines either by number (e.g., lines 1-20), by RE (between the words "foo" and "bar"), or by some combination of the two. For multiple changes, put the substitution command between braces {...}.


# replace only between lines 1 and 20
1,20 s/Johnson/White/g

# replace everywhere EXCEPT between lines 1 and 20
1,20 !s/Johnson/White/g

# replace only between words "foo" and "bar"
/foo/,/bar/ { s/Johnson/White/g; s/Smith/Wesson/g; }

# replace only from the words "ENDNOTES:" to the end of file
/ENDNOTES:/,$ { s/Schaff/Herzog/g; s/Kraft/Ebbing/g; }

Create a baseline from command line

If p1, p2 and p3 are the projects from which baseline is to be created, in command line ccm session run this command:

bash-2.05$ ccm baseline -create -p p1 -p2 -p p3 -release "-Release Tag-" -purpose "Integration Testing" -all_subprojects "-Name for the baseline-"

Please make sure that "ccm" is in your path before running the above command.