Unix scripting in bash to search logs and return a specific part of a specific log file -


dare it, windows person (please don't shoot me down soon), although have played around in linux in past (mostly command line). have process have go through once in while in essence searching log files in directory (and sub directories) filename , getting out of said log file.

my first step is

grep -ril <filename or partial filename looking for> log/*.log 

from have log filename , vi find occurs. clarify: grep looking through log files seeing if filename after -ril occurs within them.

vi log/<log filename> /<filename or partial filename looking for> 

i j couple of times find cdata, , have url need extract, in putty select, copy , paste browser. quit vi without saving.


fred1 triggered @ mon aug 31 14:09:31 nzst 2015 incoming file /u03/incoming/fred/fred.2 fred.2 start grep end grep renamed fred.2.20150831140931      <?xml version="1.0" encoding="utf-8"?>     <runresponse><runreturn><item><name>runid</name><value>1703775</value></item><item><name>runhistoryid</name><value>1703775</value></item><item><name>runreporturl</name><value>https://<servername>:<port , path>b1a&amp;sp=l0&amp;sp=l1703775&amp;sp=l1703775</value></item><item><name>displayrunreporturl</name><value><![cdata[https://<servername>:<port , path2>&sp=l1703775&sp=l1703775]]></value></item><item><name>runstarttime</name><value>08/31/15 14:09</value></item><item><name>flowresponse</name><value></value></item><item><name>flowresult</name><value></value></item><item><name>flowreturncode</name><value>not return</value></item></runreturn></runresponse>     filepath=/u03/incoming/fred&filename=fred.2.20150831140931&team=dps&direction=incoming&size=31108&time=aug 31 14:09&fts=nzlssftsd01  ---------------------------------------------------------------------------------------- fred1 triggered @ mon aug 31 14:09:31 nzst 2015 incoming file /u03/incoming/fred/fred.3 fred.3 start grep end grep renamed fred.3.20150999999999      <?xml version="1.0" encoding="utf-8"?>     <runresponse><runreturn><item><name>runid</name><value>1703775</value></item><item><name>runhistoryid</name><value>1703775</value></item><item><name>runreporturl</name><value>https://<servername>:<port , path>b1a&amp;sp=l0&amp;sp=l999999&amp;sp=l9999999</value></item><item><name>displayrunreporturl</name><value><![cdata[https://<servername>:<port , path2>&sp=l999999&sp=l999999]]></value></item><item><name>runstarttime</name><value>08/31/15 14:09</value></item><item><name>flowresponse</name><value></value></item><item><name>flowresult</name><value></value></item><item><name>flowreturncode</name><value>not return</value></item></runreturn></runresponse>     filepath=/u03/incoming/fred&filename=fred.3.20150999999999&team=dps&direction=incoming&size=31108&time=aug 31 14:09&fts=nzlssftsd01 

what want grab url in cdata[https://<servername>:<port , path2>&sp=l999999&sp=l999999] fred.3.20150999999999 indicated line renamed fred.3.20150999999999.

is possible? (and apologise xml formatting, in log file.)

thanks in advance,
tel

sed -n 's@\(.*cdata\[\)\(.*\)\(\]\].*\)@\2@p'  <logfile> 

-n suppress automatic printing of pattern space

@ - sed pattern delimiter

( ) - grouping patterns

\2 - second pattern

p - print

**update - grep file pattern **

grep -ril <filename or partial filename looking for> log/*.log | xargs sed -n "/<pattern>/,/filepath=/p" | sed -n 's@\(.*cdata\[\)\(.*\)\(\]\].*\)@\2@p' 

xargs takes output of previous command input file.

if pattern fred.3.20150999999999, first sed print matched pattern filepath= , next sed extract cdata in it.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -