LINUX programming

Moderators: ITA
Number of threads: 1339
Number of posts: 2924

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Regular expression, text replacement using simple edit Posted by Josh Code on 31 Jan 2010 at 6:35 PM
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.

sed 's/from/to/g' somefile_containing_from.txt


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;
}


using command:
sed 's/student/Student/g' student.java


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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.