09-18-2012
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.
HTML Code:
Date:20120917
**********************************************************
* BACKUP ACTIVITY STARTED *
**********************************************************
List of files to be backed up:
sample.txt
sample1.txt
File Name = sample.txt
Backup File Name: sample_bkp.txt
Begin File Backup at Tue Sep 17 12:04:54 EDT 2012
Compressing sample.txt file on Tue Sep 17 12:06:49 EDT 2012...
File Name = sample1.txt
Backup File Name: sample1_bkp.txt
Begin File Backup at Tue Sep 17 12:08:53 EDT 2012
Compressing sample1.txt file on Tue Sep 17 12:09:34 EDT 2012...
Files backed up Successfully on Tue Sep 17 12:10:07 EDT 2012
***********************************************************
* BACKUP ACTIVITY ENDED *
***********************************************************
End
Date:20120918
**********************************************************
* BACKUP ACTIVITY STARTED *
**********************************************************
List of files to be backed up:
sample.txt
sample1.txt
File Name = sample.txt
Backup File Name: sample_bkp.txt
Begin File Backup at Tue Sep 18 12:04:54 EDT 2012
Compressing sample.txt file on Tue Sep 18 12:06:49 EDT 2012...
Repository Name = sample1.txt
Backup File Name: sample1_bkp.txt
Begin File Backup at Tue Sep 18 12:08:53 EDT 2012
Compressing sample1.txt file on Tue Sep 18 12:09:34 EDT 2012...
Files backed up Successfully on Tue Sep 18 12:10:07 EDT 2012
***********************************************************
* BACKUP ACTIVITY ENDED *
***********************************************************
End
I want to pass the date as an input and it should extract the information based on the given date. Say for example, if I pass 20120918 as an input to the log file, it should return the rows corresponding to that date.
I tried awk but I am unable to generate the desired output. I tried the following. Let me know if there is a better way to do it.
HTML Code:
awk '/End$/{exit}/Date:`date +%Y%m%d`$/{f=1}f' backup_files.log
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I want to write a small script to search for a text in file and when its found I want to print the next line.
I try to write that script but I could not manage it, I just write the following script the find the exact line but I want the next line.
$ sed -n -e '/Form not/p' test.txt... (2 Replies)
Discussion started by: alijassim
2 Replies
2. Shell Programming and Scripting
hello
have a file1
H87I
Y788O
T347U
J23U
and
file2 J23U U887Y I99U T556U
file3 I99O J99T F557J
file4 N99I T666U R55Y
file5 H87I T347U
file6 H77U R556Y E44T
file7 Y788O K98U H8I
May be using script we can use file1 to search for all the files
and have the output
H87I file5... (3 Replies)
Discussion started by: cdfd123
3 Replies
3. Shell Programming and Scripting
Hi Guys,
I had file as
typedef struct {
char TrailerType1;
char TrailerTxt1;
}Trailer;
typedef struct {
char PfigMoneyType;
char PfigMoneyvalue;
}PfigMoney;
i need to print the lines within the search pattern. if i give the search pattern as... (3 Replies)
Discussion started by: manosubsulo
3 Replies
4. Shell Programming and Scripting
Hi all
I am searching for a pattern in a file .
The file content is in a single line.If am doing a grep or sed for the a particular pattern am getting whole file.
I want the result in different lines.
attaching the file for reference
search pattern "/xxxxxx/hhhh/tttttttt/sss/" and... (4 Replies)
Discussion started by: sparks
4 Replies
5. Shell Programming and Scripting
Masters,
I have a text file in the following format.
vrsonlviee RVEBAALSKE
lyolzteglx UUOSIWMDLR
pcybtapfee DKGFJBHBJO
ozhrucfeau YQXATYMGJD
cjwvjolrcv YDHALRYQTG
mdukphspbc CQZRIOWEUB
nbiqomzsgw DYSUBQSSPZ
xovgvkneav HJFQQYBLAF
boyyzdmzka BVTVUDHSCR
vrsonlviee TGTKUCUYMA... (2 Replies)
Discussion started by: genehunter
2 Replies
6. UNIX for Dummies Questions & Answers
I have a file called po.txt. Here is the content of the file:
<!DOCTYPE PurchaseOrderMessage (View Source for full doctype...)>
- <PurchaseOrder>
- <Header>
<MessageId>cdb3062b-685b-4cd5-9633-013186750e10</MessageId>
<Timestamp>2011-08-01T13:47:23.536-04:00</Timestamp>
</Header>
-... (4 Replies)
Discussion started by: webbi
4 Replies
7. Shell Programming and Scripting
I have the following code:
print @testarray;
which returns:
8
8
8
9
How do I return the array like this:
The output is: 8, 8, 8, 9 (5 Replies)
Discussion started by: streetfighter2
5 Replies
8. Shell Programming and Scripting
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
9. UNIX for Beginners Questions & Answers
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... (1 Reply)
Discussion started by: Prathi
1 Replies
10. UNIX for Beginners Questions & Answers
Hi,
I am Searching for Multiple strings in a given date range and print the Group if they exists. the below is the format:
-------------------------------------------------------------------------------------------------------------------------
ID: FIRST ID
MESSAGE: Event Message... (5 Replies)
Discussion started by: linuxuser999
5 Replies