Grep command notes
Last edit: 2021-12-20
---
Grep for one result Y, but then show only those results that have a line starting with X This came in handy when we had an instance where we needed to find an error, but then find all rows in the log related to that error by thread number. In the example below, we grep for the thread number in the log, but then look for all lines beginning with a certain time, so we can see what was going on in that thread at the same time as the error.
---
grep '[Y]' SystemOut_11.10.07_10.30.53.log | grep ^'[X]'
Example:
grep '0000e5bb' SystemOut_11.10.07_10.30.53.log | grep ^'\[10/7/11 9:4'
----------
Check out http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_02.html
-------------------------
Parse out an ID or something of that nature using AWK.
---
awk -F">" '{print $2}' someLogFile.log
-F option says to treat ">" as a marker around which to break the line.
'{print $2}' says to print the block of text in spot #2 following that
You can pipe these together. Say you have a log entry with a bunch of rows like:
<someXMLCell>123456789</someXMLCell>
...and you want to get out all the ID numbers.
You can do:
grep 'someXMLCell' myLogFile.log | awk -F">" '{print $2}' | awk -F"<" '{print $1}'
And that will return the values:
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354