Regular expression, text replacement using simple edit - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Regular expression, text replacement using simple edit

I'm trying to make a shell script that can change class names in source files.

The following will run without an error message but it doesn't do exactly what I want.

[code]sed 's/from/to/g' somefile_containing_from.txt[/code]

That command will replace all occurrences of the word "from" to "to" while printing out the contents of the file. What I need is something where it only matches when there is a non-letter before and after the "from".

Due to the problem in the above command, the following undesired replacements happen:

File contents for before running through sed command:
public class student
private student[] topstudent;

using command:
[code]sed 's/student/Student/g'[/code]

Prints the following:
public class Student
private Student[] topStudent;

Notice that the variable name changed because it found "student" in the output even though topstudent was not the class name.
Sign In or Register to comment.