Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2003

Tip: Looking for answers? Try searching our database.

Search and replace a line in a java file

Thread view: 
Mikael Petterson - 28 Sep 2003 17:07 GMT
Hi,

I am curiuos to find out if it is possible to find string lines in a
java file:

public static final String <Variable name with all caps> = ;

and replace it with:

public static final String <Variable name with all caps> = "";

Is there a way to replace lines looking like the first line with the
last line. The name before equal sign is different for each line.

I am thinking of using a shell script or regexp in java 1.4 (That is why
I post in two places).

Regards,

//Mikael
Ed Morton - 28 Sep 2003 17:20 GMT
> Hi,
>
[quoted text clipped - 16 lines]
>
> //Mikael

Pretty trivial with sed:

sed 's/^\(public static final String [A-Z0-9_]* = \);/\1"";/' filename.java

I'm assuming your variable name can include digits and underscores as
well as being all upper-case letters.

Regards,

    Ed.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.