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
LOOK(1) 						    BSD General Commands Manual 						   LOOK(1)

NAME
look -- display lines beginning with a given string SYNOPSIS
look [-bdf] [-t termchar] string [file ...] DESCRIPTION
The look utility displays any lines in file which contain string as a prefix. If file is not specified, the file /usr/share/dict/words is used, only alphanumeric characters are compared and the case of alphabetic char- acters is ignored. The following options are available: -b Use a binary search on the given word list. If you are ignoring case with -f or ignoring non-alphanumeric characters with -d, the file must be sorted in the same way. Please note that these options are the default if no filename is given. See sort(1) for more information on sorting files. -d Dictionary character set and order, i.e., only alphanumeric characters are compared. -f Ignore the case of alphabetic characters. -t Specify a string termination character, i.e., only the characters in string up to and including the first occurrence of termchar are compared. ENVIRONMENT
The LANG, LC_ALL and LC_CTYPE environment variables affect the execution of the look utility. Their effect is described in environ(7). FILES
/usr/share/dict/words the dictionary EXIT STATUS
The look utility exits 0 if one or more lines were found and displayed, 1 if no lines were found, and >1 if an error occurred. COMPATIBILITY
The original manual page stated that tabs and blank characters participated in comparisons when the -d option was specified. This was incor- rect and the current man page matches the historic implementation. look uses a linear search by default instead of a binary search, which is what most other implementations use by default. SEE ALSO
grep(1), sort(1) HISTORY
A look utility appeared in Version 7 AT&T UNIX. BUGS
Lines are not compared according to the current locale's collating order. Input files must be sorted with LC_COLLATE set to 'C'. BSD
July 17, 2004 BSD
All times are GMT -4. The time now is 07:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy