Unix/Linux Go Back    


BSD BSD, sometimes called Berkeley Unix, is a Unix operating system developed by the Computer Systems Research Group of the UC Berkeley.

Searching in multiple files

BSD


Tags
find, grep, script, search

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-01-2014
jim john jim john is offline
Registered User
 
Join Date: Sep 2014
Last Activity: 25 February 2015, 8:08 AM EST
Location: Cochin ,India
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Searching in multiple files

I am new to unix and I would like to search multiple log files to find earliest occurrence of a text.
Ex:
Say I have 10 logs file each ending with .log and I want to find the text “CustomeError” .
I want to find the which log file “CustomeError” comes first and lines which surround’s “CustomeError”.
Also I would like to find the last occurrence of “CustomError”
Every line in my log file starts with date and time.
Ex :

Code:
8/31/14 7:53:05:954 
9/1/14 0:21:08:050

I am OK with script or single command.

Last edited by Franklin52; 09-01-2014 at 10:06 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old Unix and Linux 09-01-2014
RavinderSingh13 RavinderSingh13 is online now Forum Advisor  
Registered User
 
Join Date: May 2013
Last Activity: 27 February 2017, 1:02 PM EST
Location: Chennai
Posts: 2,377
Thanks: 529
Thanked 1,111 Times in 1,001 Posts
Hello Jim,

Welcome to the forum, as per forum rules could you please use code tags for commands and codes before posting you can also use preview post option for same.
Also kindly do let us know the input flle and expected output for same with OS details, it will help us to guide you.


Thanks,
R. Singh
Sponsored Links
    #3  
Old Unix and Linux 09-01-2014
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 27 February 2017, 12:43 PM EST
Location: Aachen, Germany
Posts: 10,342
Thanks: 245
Thanked 3,169 Times in 2,924 Posts
Sounds like an application for grep -C, if that is available on your system (it is on FreeBSD).
If you really need to search for “CustomeError”, “CustomError”, or even “CustomerError”, put a wildcard into the search pattern.
    #4  
Old Unix and Linux 09-01-2014
jim john jim john is offline
Registered User
 
Join Date: Sep 2014
Last Activity: 25 February 2015, 8:08 AM EST
Location: Cochin ,India
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Example input file:
I will have more files like this.
See in this file i want to find the line

Code:
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.abc.MyClass CustomeError"

which is the earliest occurrence of custome error.
I want my search to extend to all the log files in the folder and find first "CustomeError" in log file.

Code:
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.abc.MyClass CustomeError"
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.abc.MyClass CustomeError"
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[9/1/14 0:21:08:050 EDT] 00000030 SystemErr     R     at com.abc.MyClass CustomeError"


Last edited by Franklin52; 09-01-2014 at 10:02 AM.. Reason: Please use code tags
Sponsored Links
    #5  
Old Unix and Linux 09-04-2014
MadeInGermany MadeInGermany is online now Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 27 February 2017, 12:38 PM EST
Location: Simplicity
Posts: 3,425
Thanks: 263
Thanked 1,130 Times in 1,025 Posts
Perhaps your grep can stop after the 1st match

Code:
grep -m 1 "CustomeError" *.log

Also display the surrounding lines ("Context"):

Code:
grep -m 1 -C 1 "CustomeError" *.log

The Following User Says Thank You to MadeInGermany For This Useful Post:
rbatte1 (09-08-2014)
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help on searching for a string on multiple files newbie_01 Shell Programming and Scripting 2 04-17-2014 07:14 AM
Searching across multiple files if pattern is available in all files searched novice_man Shell Programming and Scripting 6 02-13-2011 10:02 PM
Searching a word in multiple files rakesh_411 Shell Programming and Scripting 3 10-10-2010 05:28 AM
Searching for multiple patterns in files bornon2303 Shell Programming and Scripting 5 02-25-2010 10:05 AM
Searching multiple files with multiple expressions Anahka Shell Programming and Scripting 6 01-07-2004 06:24 PM



All times are GMT -4. The time now is 02:07 PM.