Search for word in huge logfile and need to continue to print few lines from that line til find date


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Search for word in huge logfile and need to continue to print few lines from that line til find date
# 1  
Old 04-24-2019
Search for word in huge logfile and need to continue to print few lines from that line til find date

Guys i need an idea for one logic..in shell scripting am struggling with a logic...So the thing is... i need to search for a word in a huge log file and i need to continue to print few more lines from that line and the consecutive line has to end when it finds the line with date..because i know only the date which is first field...

Eg:

Am having huge log file -file.log
I need to grep a word like "ERROR" from that file so the output will start with date-2019-04-24
2019-04-24 ........
The problem is am getting only that line while using grep and awk command on searching for a pattern. But i need to few more lines after searching that word in that log file till the lines which start with the date...why because to get the complete content of that error.
So when i get another line which start with 2019-04-24 then till that content i need to print...

Am trying so far...can anyone help
# 2  
Old 04-24-2019
it always it helps to provide a sample representative data snippet and the desired output (using code tags).
Also it could help if you provide what you've tried so far...

Last edited by vgersh99; 04-24-2019 at 05:21 PM..
These 2 Users Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

(n)awk: print regex search output lines in one line

Hello. I have been looking high and low for the solution for this. I seems there should be a simple answer, but alas. I have a big xml file, and I need to extract certain information from specific items. The information I need can be found between a specific set of tags. let's call them... (2 Replies)
Discussion started by: Tobias-Reiper
2 Replies

2. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

4. Shell Programming and Scripting

Search string and print the above line and below lines?.

if the first string matches then print the previous line and current line and also print the following lines if the other string search matches. Input ------ TranTime 2012 10 12 The Record starts here Accountnumber: 4632473431274 TxnCode 323 TranID 329473242834 ccsdkcnsdncskd... (7 Replies)
Discussion started by: laknar
7 Replies

5. Shell Programming and Scripting

search for a date and print the contents below the line

Hi, We have a script which takes the backup of some files and writes the output into a log file for each run on a daily basis. Following is the extract from the log file. Date:20120917 ********************************************************** * BACKUP ACTIVITY STARTED ... (5 Replies)
Discussion started by: svajhala
5 Replies

6. Shell Programming and Scripting

Search words in a line and print next 15 lines.

I have a text file ( basically a log file) and i have 2 words (alpha, beta), Now i want to search these two words in one line and then print next 15 lines in a temp file. there would be many lines with alpha and beta But I need only last occurrence with "alpha" and "beta" and next 15 lines. ... (4 Replies)
Discussion started by: kashif.live
4 Replies

7. Shell Programming and Scripting

find a word and print n lines before and after the match

how to find a word and print n lines before and after the match until a blank line is encounterd (14 Replies)
Discussion started by: chidori
14 Replies

8. Shell Programming and Scripting

Print lines after the search string until blank line is found

All I want is to look for the pattern in the file...If I found it at # places... I want print lines after those pattern(line) until I find a blank line. Log EXAMPLE : MT:Exception caught The following Numbers were affected: 1234 2345 2346 Error java.lang.InternalError:... (3 Replies)
Discussion started by: prash184u
3 Replies

9. Shell Programming and Scripting

How to find and print the last word of each line from a text file

Can any one help us in finding the the last word of each line from a text file and print it. eg: 1st --> aaa bbbb cccc dddd eeee ffff ee 2nd --> aab ered er fdf ere ww ww f the o/p should be a below. ee f (1 Reply)
Discussion started by: naveen_sangam
1 Replies

10. Shell Programming and Scripting

Search word in a line and print earlier pattern match

Hi All, I have almost 1000+ files and I want to search specific pattern. Looking forwarded your input. Search for: word1.word2 (Which procedure contain this word, I need procedure name in output. Expected output: procedure test1 procedure test2 procedure test3 procedure test4 ... (7 Replies)
Discussion started by: susau_79
7 Replies
Login or Register to Ask a Question