grep lines from the previous day's file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep lines from the previous day's file
# 1  
Old 11-22-2011
grep lines from the previous day's file

I have files called printfile.log.1121, printfile.log.1122, etc where 1121 and 1122 are the date of the file creation.

The file contents are like:
PHP Code:
================================================================================
User    d_prod
Env     
d_prod
Dir     
= /cerner/d_prod/ccluserdir
Date    
Mon Nov 21 00:22:23 EST 2011
From    
=   d_prod 4415706       1  65 23:52:03      -  0:47 cer_exe/cpm_srvscript PROD * * -off
er 
-factor 1
Cmd     
= [/cerner/w_standard/prod2003_02/forms/print_file --c1 -Piphb3h27p1 -fpost /cerner/d_
prod
/ccluserdir/ccltemp4415706d002a.dat]

File   = /cerner/d_prod/print/ccltemp4415706d002a.dat.tmp.1121002223
Queue   
iphb3h27p1
Copies  
1
Forms   
post
Library 
= /cerner/w_standard/prod2003_02/forms/formhp5.cfg
Init    
= [1]   /cerner/w_standard/prod2003_02/forms/formhp5/post
Reset   
= [0]

Spawn:  [pr  ---l66 -w132 /cerner/d_prod/print/ccltemp4415706d002a.dat.tmp.1121002223 |
                
cat /cerner/w_standard/prod2003_02/forms/formhp5/post -  |
                
qprt  -ds -N 1 -P iphb3h27p1 -/cerner/d_prod/print/ccltemp4415706d002a.dat.tmp
.1121002223
]

================================================================================
User    d_prod
Env     
d_prod
Dir     
= /cerner/d_prod/ccluserdir
Date    
Mon Nov 21 00:22:38 EST 2011
From    
=   d_prod 7000198       1  51 23:51:39      -  0:44 cer_exe/cpm_srvscript PROD * * -off
er 
-factor 1
Cmd     
= [/cerner/w_standard/prod2003_02/forms/print_file --c1 -Piphb3h27p1 -fpost /cerner/d_
prod
/ccluserdir/ccltemp7000198d004a.dat]

File   = /cerner/d_prod/print/ccltemp7000198d004a.dat.tmp.1121002238
Queue   
iphb3h27p1
Copies  
1
Forms   
post
Library 
= /cerner/w_standard/prod2003_02/forms/formhp5.cfg
Init    
= [1]   /cerner/w_standard/prod2003_02/forms/formhp5/post
Reset   
= [0]

Spawn:  [pr  ---l66 -w132 /cerner/d_prod/print/ccltemp7000198d004a.dat.tmp.1121002238 |
                
cat /cerner/w_standard/prod2003_02/forms/formhp5/post -  |
                
qprt  -ds -N 1 -P iphb3h27p1 -/cerner/d_prod/print/ccltemp7000198d004a.dat.tmp
.1121002238
]

================================================================================
User    d_prod
Env     
d_prod
Dir     
= /cerner/d_prod/ccluserdir
Date    
Mon Nov 21 00:22:39 EST 2011
From    
=   d_prod 5193848       1  88 23:46:50      -  1:00 cer_exe/cpm_srvscript PROD * * -off
er 
-factor 1
Cmd     
= [/cerner/w_standard/prod2003_02/forms/print_file --c1 -Piphb3h27p1 -fpost /cerner/d_
prod
/ccluserdir/ccltemp5193848d004a.dat]

File   = /cerner/d_prod/print/ccltemp5193848d004a.dat.tmp.1121002239
Queue   
iphb3h27p1
Copies  
1
Forms   
post
Library 
= /cerner/w_standard/prod2003_02/forms/formhp5.cfg
Init    
= [1]   /cerner/w_standard/prod2003_02/forms/formhp5/post
Reset   
= [0]

Spawn:  [pr  ---l66 -w132 /cerner/d_prod/print/ccltemp5193848d004a.dat.tmp.1121002239 |
                
cat /cerner/w_standard/prod2003_02/forms/formhp5/post -  |
                
qprt  -ds -N 1 -P iphb3h27p1 -/cerner/d_prod/print/ccltemp5193848d004a.dat.tmp
.1121002239
]

================================================================================
User    d_prod
Env     
d_prod
Dir     
= /cerner/d_prod/ccluserdir
Date    
Mon Nov 21 00:23:40 EST 2011
From    
=   d_prod 2986152       1   4 13:30:43      -  0:06 cer_exe/srv_drvr PROD * * /cerner/w
_standard
/prod2003_02/aixrs6000/scs_srvcoltn
Cmd     
= [/cerner/w_standard/prod2003_02/forms/print_file --c1 -Plb66w7a -fzbdyn16rv /cerner/
d_prod/ccluserdir/ccltemp2986152d010a.dat]

File   = /cerner/d_prod/print/ccltemp2986152d010a.dat.tmp.1121002339
Queue   
lb66w7a
Copies  
1
Forms   
zbdyn16rv
Library 
= /cerner/w_standard/prod2003_02/forms/formzebra.cfg
Init    
= [3]   /cerner/w_standard/prod2003_02/forms/formzebra/zbdyn16.txt
                
/cerner/w_standard/prod2003_02/forms/formzebra/zbrot.txt
                
/cerner/w_standard/prod2003_02/forms/formzebra/zbvirt.txt
Reset   
= [0]

Spawn:  [pr  --w132 /cerner/d_prod/print/ccltemp2986152d010a.dat.tmp.1121002339 |
                
cat /cerner/w_standard/prod2003_02/forms/formzebra/zbdyn16.txt /cerner/w_standar
d
/prod2003_02/forms/formzebra/zbrot.txt /cerner/w_standard/prod2003_02/forms/formzebra/zbvirt.tx
-  |
                
qprt  --dp -N 1 -P lb66w7a -/cerner/d_prod/print/ccltemp2986152d010a.dat.tmp
.1121002339
]

================================================================================ 
I need to pull out three items from the file. It will be running on cron, so I need to pull the items from the previous day's file (i.e. printfile.log.1121 on 11/22).

Off of the file, I need to have these.

i.e.

PHP Code:
Date    Mon Nov 21 00:33:10 EST 2011
Queue   
iphb3h27p1
Forms   
post 
For the output format, I like to have them in a row with a delimiter pipe (|) so that I can run things in Excel.

PHP Code:
lb66w7a   |   post  |  00:23:40
iphb3h27p1 
post  00:33:10
etc
etc 
Please advise.
# 2  
Old 11-22-2011
OK.. a start?

Code:
$ cat sample9.txt | grep -e "^Date" -e "^Queue" -e "^Forms"
Date    = Mon Nov 21 00:22:23 EST 2011
Queue   = iphb3h27p1
Forms   = post
Date    = Mon Nov 21 00:22:38 EST 2011
Queue   = iphb3h27p1
Forms   = post
Date    = Mon Nov 21 00:22:39 EST 2011
Queue   = iphb3h27p1
Forms   = post
Date    = Mon Nov 21 00:23:40 EST 2011
Queue   = lb66w7a
Forms   = zbdyn16rv

And the rest, a little weird, but works...
Code:
$ cat sample9.txt | grep -e "^Date" -e "^Queue" -e "^Forms" | sed "s/Date/~Date/g" | tr "\n" " " | tr "~" "\n" | awk '{print $11 " | " $14 " | " $6}'

iphb3h27p1 | post | 00:22:23
iphb3h27p1 | post | 00:22:38
iphb3h27p1 | post | 00:22:39
lb66w7a | zbdyn16rv | 00:23:40

This User Gave Thanks to joeyg For This Post:
# 3  
Old 11-22-2011
here's how to get the data out of A file:
Code:
nawk '$1=="Date" {d=$(NF-2);next} $1=="Queue" {q=$NF;next} $1=="Forms"{print q, $NF, d}' OFS='|' printfile.log.1121

Search the forums how to get the previous day date - there're multiple threads of the subject including the one in the FAQ area.
This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 12-01-2011
Thanks much. It works great!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grep and print the next and previous N lines after the hit

Hello, I know that gnu grep has option of -A and -B to extra previous and next lines. But I'm using HP UX and its grep does not support these options. BID="0/0/6/1/1.145.17.255.0.0.0" I need to search a file using $BID and get next 5 lines and previous 5 lines separately. Please... (1 Reply)
Discussion started by: reddyr
1 Replies

2. Shell Programming and Scripting

View file on previous day

Hi Expert, I am new to UNIX , I am looking for a script which can show me list of file created on previous date within specified directory. Regards, Mack (9 Replies)
Discussion started by: mackjack
9 Replies

3. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

4. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

5. Shell Programming and Scripting

Script to check if last modified day is previous day

Hi, I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it. For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Discussion started by: hegdepras
1 Replies

6. Shell Programming and Scripting

finding the previous day date and creating a file with date

Hi guys, I had a scenario... 1. I had to get the previous days date in yyyymmdd format 2. i had to create a file with Date inthe format yyyymmdd.txt format both are different thanks guys in advance.. (4 Replies)
Discussion started by: apple2685
4 Replies

7. Shell Programming and Scripting

Finding lines matching the Pattern and their previous lines in a file

Hi, I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using: grep -w 'Possible network disconnect' file_name. But I am more interested in getting the timing of these events which are... (7 Replies)
Discussion started by: sagarparadkar
7 Replies

8. Shell Programming and Scripting

getting previous day.

Hi, i am developing a script for my project. In my script i need to check some conditions based upon some values. in that one value is the previous date. with the previous date i need to check and process some values. I have a function with me retrieve the yesterdays date. But now i have a... (6 Replies)
Discussion started by: intiraju
6 Replies

9. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

10. Shell Programming and Scripting

Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things: STEP 1) Verify that the file arrived in morning. STEP 2) Compare the file size of the current... (3 Replies)
Discussion started by: rbknisely
3 Replies
Login or Register to Ask a Question