Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
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 student.java before running through sed command:
public class student
private student topstudent;
[code]sed 's/student/Student/g' student.java[/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.