Sponsored Content
Top Forums Shell Programming and Scripting List file's name and search string's Line Post 302557112 by linuxadmin on Tuesday 20th of September 2011 11:58:08 AM
Old 09-20-2011
is it possible

ahamed,

i have a Java project with more than 5000 java/jsp files.

In about all the java/jsp files there is System.out.println.

I need to comment all the //System.out.println line from all the java files.
But need to see which are all the files before commenting. --> This [commenting] I will do later

Now my need is to list all the java files containing system.out.println:
and the output i need is :
Code:
/home/me/project/file1.java [system.out.println containing file name]
somejavacode [second line before system.out.println]
somejavacode [first line before system.out.println]
System.out.println("something");
somejavacode [first line after system.out.println]
somejavacode [second line after system.out.println]
somejavacode [third line after system.out.println]

/home/me/project/file156.java [system.out.println containing file name]
somejavacode [second line before system.out.println]
somejavacode [first line before system.out.println]
System.out.println("something");
somejavacode [first line after system.out.println]
somejavacode [second line after system.out.println]
somejavacode [third line after system.out.println]

/home/me/project/file871.java [system.out.println containing file name]
somejavacode [second line before system.out.println]
somejavacode [first line before system.out.println]
System.out.println("something");
somejavacode [first line after system.out.println]
somejavacode [second line after system.out.println]
somejavacode [third line after system.out.println]
etc..

Code:
Here is an Example java file convertBoolean.java
/*
  Convert java Boolean object to String object Example
  This example shows how to convert java Boolean object into String object.
*/
 
public class JavaBooleanToStringExample {
 
  public static void main(String[] args) {
    //construct Boolean object
    Boolean blnObj = new Boolean("true");
 
    //use toString method of Boolean class to convert it into String
    String str = blnObj.toString();
    System.out.println(str);
  }
}

I need the Output of our command as:
Code:
..
..
..
/home/me/project/convertBoolean.java
    //use toString method of Boolean class to convert it into String
    String str = blnObj.toString();
    System.out.println(str);
  }
}
..
..
..

Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

2. UNIX for Dummies Questions & Answers

Search String in File List

Hi, I have a list of files which can be identified as abcd*.xml where * represent multiple timestamps for multiple files. I need to do following checks 1. Find number of files (which we get by doing following) FILECOUNT=`ls -ltr /dir/abcd*.xml | wc -l` 2. If check 1 gives '1' as... (2 Replies)
Discussion started by: dsrookie
2 Replies

3. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

4. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

5. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

6. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

7. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

8. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

9. Shell Programming and Scripting

Search a string in a file and change another in the line

I did it myself (0 Replies)
Discussion started by: apenkov
0 Replies

10. UNIX for Beginners Questions & Answers

Need help with how to search a file for a variable string and delete that line

Hi, I have a working script. It does what I am intending it to but a bit confused whether the sed part is supposed to be working or not. Further down is the script with the sed part that should have been working but not and the grep -v part which is the workaround that I am using at the... (10 Replies)
Discussion started by: newbie_01
10 Replies
tnameserv(1)						      General Commands Manual						      tnameserv(1)

NAME
tnameserv - Java IDL name server starter script SYNOPSIS
tnameserv -ORBInitialPort portNumber DESCRIPTION
The CORBA COS (Common Object Services) Naming Service provides a tree-like directory for object references much like a filesystem provides a directory structure for files. The Naming Service provided with Java IDL is a simple implementation of the COS Naming Service specifica- tion. Object references are stored in the namespace by name and each object reference-name pair is called a name binding. Name bindings may be organized under naming contexts. Naming contexts are themselves name bindings and serve the same organizational function as a file system subdirectory. All bindings are stored under the initial naming context. The initial naming context is the only persistent binding in the namespace; the rest of the namespace is lost if the Java IDL name server process halts and restarts. For an applet or application to use COS naming, its ORB must know the name and port of a host running a naming service or have access to a stringified initial naming context for that name server. The naming service can either be the Java IDL name server or another COS-compli- ant name service. USAGE
Starting the Java IDL Name Server You must start the Java IDL name server before an application or applet that uses its naming service. Installation of the Java IDL product creates a script named tnameserv that starts the Java IDL name server. Start the name server so it runs in the background. If you do not specify otherwise, the Java IDL name server listens on port 900 for the bootstrap protocol used to implement the ORB resolve_initial_references() and list_initial_references() methods. Specify a different port, for example, 1050, as follows: example% tnameserv -ORBInitialPort 1050 Clients of the name server must be made aware of the new port number. Do this by setting the org.omg.CORBA.ORBInitialPort property to the new port number when creating the ORB object. Stopping the Java IDL Name Server To stop the Java IDL name server, use the relevant operating system command, such as kill(1). Note that names registered with the Java IDL name service disappear when the server is terminated. Sample Client: Adding Objects The following sample program illustrates how to add names to the namespace. It is a self-contained Name Server client that creates the following simple tree. Initial Naming Context / / plans personal / / calendar schedule In this example, "plans" is an object reference and "personal" is a naming context that contains two object references: "calendar" and "schedule". import java.util.Properties; import org.omg.CORBA.*; import org.omg.CosNaming.*; public class NameClient { public static void main(String args[]) { try { In the above section, Starting the Java IDL Name Server, the nameserver was started on port 1050. The following code ensures that the client program is aware of this port number. Properties props = new Properties(); props.put("org.omg.CORBA.ORBInitialPort", "1050"); ORB orb = ORB.init(args, props); The following code obtains the initial naming context and assigns it to ctx. The second line copies ctx into a dummy object reference, objref, that we will attach to various names and add into the namespace. NamingContext ctx = NamingContextHelper.narrow (orb.resolve_initial_references("NameService")); NamingContext objref = ctx; The following code creates a name "plans" of type "text" and binds it to our dummy object reference. "plans" is then added under the ini- tial naming context using rebind. The rebind method allows us to run this program over and over again without getting the exceptions we would get from using bind. NameComponent nc1 = new NameComponent("plans", "text"); NameComponent[] name1 = {nc1}; ctx.rebind(name1, objref); System.out.println("plans rebind sucessful!"); The following code creates a naming context called "Personal" of type "directory". The resulting object reference, ctx2, is bound to the name and added under the initial naming context. NameComponent nc2 = new NameComponent("Personal", "directory"); NameComponent[] name2 = {nc2}; NamingContext ctx2 = ctx.bind_new_context(name2); System.out.println("new naming context added.."); The remainder of the code binds the dummy object reference using the names "schedule" and "calendar" under the "Personal" naming context (ctx2). NameComponent nc3 = new NameComponent("schedule", "text"); NameComponent[] name3 = {nc3}; ctx2.rebind(name3, objref); System.out.println("schedule rebind sucessful!"); NameComponent nc4 = new NameComponent("calender", "text"); NameComponent[] name4 = {nc4}; ctx2.rebind(name4, objref); System.out.println("calender rebind sucessful!"); } catch (Exception e) { e.printStackTrace(System.err); } } } Sample Client: Browsing the Namespace The following sample program illustrates how to browse the namespace. import java.util.Properties; import org.omg.CORBA.*; import org.omg.CosNaming.*; public class NameClientList { public static void main(String args[]) { try { In the above section, Starting the Java IDL Name Server, the nameserver was started on port 1050. The following code ensures that the client program is aware of this port number. Properties props = new Properties(); props.put("org.omg.CORBA.ORBInitialPort", "1050"); ORB orb = ORB.init(args, props); The following code obtains the initial naming context. NamingContext nc = NamingContextHelper.narrow (orb.resolve_initial_references("NameService")); The list method lists the bindings in the naming context. In this case, up to 1000 bindings from the initial naming context will be returned in the BindingListHolder; any remaining bindings are returned in the BindingIteratorHolder. BindingListHolder bl = new BindingListHolder(); BindingIteratorHolder blIt= new BindingIteratorHolder(); nc.list(1000, bl, blIt); The following code gets the array of bindings out of the returned BindingListHolder. If there are no bindings, the program ends. Binding bindings[] = bl.value; if (bindings.length == 0) return; The remainder of the code loops through the bindings and prints the names out. for (int i=0; i < bindings.length; i++) { // get the object reference for each binding org.omg.CORBA.Object obj = nc.resolve (bindings[i].binding_name); String objStr = orb.object_to_string(obj); int lastIx = bindings[i].binding_name.length-1; // check to see if this is a naming context if (bindings[i].binding_type == BindingType.ncontext) { System.out.println ("Context: " + bindings[i].binding_name[lastIx].id); } else { System.out.println ("Object: " + bindings[i].binding_name[lastIx].id); } } } catch (Exception e) { e.printStackTrace(System.err); } } } SEE ALSO
kill(1) 13 June 2000 tnameserv(1)
All times are GMT -4. The time now is 06:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy