Java Reference
In-Depth Information
Here are a few more substitution examples along with an explanation
for each.
.,$s/here/eternity/
From here to the end of the file, replace here with eternity .
27,$-5s/lost/found/
From line 27 to the 5th line prior to the end of the file, replace lost with
found .
s/here/now/
Replace here with now , on the current line only.
Each line that has a match will do the substitution on only the first occur-
rence of the string. If you want to change all occurrences on those lines, you
append a g (for “global” substitution) to the end of the command. Consider
this snippet of Java:
class tryout
{
int tryout;
tryout(int startval) { // make a new tryout
tryout = startval;
} // tryout constructor
// a tryout-like resetting
public void
setTryout(int toval) {
tryout = toval;
}
// willfindtryoutinhere
} // class tryout
1,$s/tryout/sample/
Works as expected except for line 5, where “tryout” appears as the
constructor name but also in the comment.
1,$s/tryout/sample/g
Works better (note the trailing g ). But neither command can deal with
“Tryout” in the setTryout method name. That's because of the uppercase
“T”, which doesn't match “tryout”.
Search WWH ::




Custom Search