[Instance] Regular Expressions use grep and sed to process log Content,
Obtain required content
App. Log File Content:
00:00:01, 516 info [COM. tt. BB. thread. Control]-socket connection:/182.105.83.33: 53217
10:00:06, 555 info [COM. tt. BB. thread. Control]-socket connection:/182.113.83.51: 53249
20:00:11, 587 info [COM. tt. BB. thread. Control]-socket connection:/182.114.83.66: 53281
15:09:16, 611 info [COM. tt. BB. thread. Control]-socket connection:/182.115.83.17: 53313
15:10:01, 408 info [COM. tt. BB. thread. Control]-socket connection:/182.115.83.17: 53523
04:01:21, 648 info [COM. tt. BB. thread. Control]-socket connection:/182.116.83.58: 53311
04:10:21, 631 info [COM. tt. BB. thread. Control]-socket connection:/182.116.83.58: 53551
04:20:21, 608 info [COM. tt. BB. thread. Control]-socket connection:/182.116.83.58: 53301
04:30:21, 655 info [COM. tt. BB. thread. Control]-socket connection:/182.116.83.58: 53336
Requirement 1:Obtain only one IP address of the same date ).
Solution:
This method uses a regular expression in the SED command. Although it is more complex, it is worth advocating.
#Cat app. log | SED's # \ ([0-9] \ {2 \} \): \ ([0-9] \ {2 \}\). * connection: // # G'
182.105.83.33: 53217
2014-09-12 182.113.83.51: 53249
2014-09-13 182.114.83.66: 53281
182.115.83.17: 53313
182.115.83.17: 53523
2014-09-15 182.116.83.58: 53311
2014-09-15 182.116.83.58: 53551
2014-09-15 182.116.83.58: 53301
2014-09-15 182.116.83.58: 53336
#Cat app. log | SED's # \ ([0-9] \ {2 \} \): \ ([0-9] \ {2 \}\). * connection: // # G' | SED's #: \ ([0-9] \ {4, \} \) # G'
2014-09-11 182.105.83.33
2014-09-12 182.113.83.51
2014-09-13 182.114.83.66
2014-09-14 182.115.83.17
2014-09-14 182.115.83.17
2014-09-15 182.116.83.58
2014-09-15 182.116.83.58
2014-09-15 182.116.83.58
2014-09-15 182.116.83.58
#Cat app. log | SED's # \ ([0-9] \ {2 \} \): \ ([0-9] \ {2 \}\). * connection: // # G' | SED's #: \ ([0-9] \ {4, \} \) # G' | uniq
2014-09-11 182.105.83.33
2014-09-12 182.113.83.51
2014-09-13 182.114.83.66
2014-09-14 182.115.83.17
2014-09-15 182.116.83.58
Requirement 2:Only get the same date, the same time period (get to the "time" location), there is only one IP address (deduplication ).
Solution:
This method uses a regular expression in the SED command. Although it is more complex, it is worth advocating.
#Cat app. log | SED's #: \ ([0-9] \ {2 \} \), \ ([0-9] \ {3 \}\). * connection: // # G'
182.105.83.33: 53217
182.113.83.51: 53249
182.114.83.66: 53281
182.115.83.17: 53313
182.115.83.17: 53523
01 182.116.83.58: 53311
182.116.83.58: 53551
182.116.83.58: 53301
182.116.83.58: 53336
#Cat app. log | SED's #: \ ([0-9] \ {2 \} \), \ ([0-9] \ {3 \}\). * connection: // # G' | SED's #: \ ([0-9] \ {4, \} \) # G' | uniq
182.105.83.33
182.113.83.51
182.114.83.66
182.115.83.17
182.115.83.17
01 182.116.83.58
182.116.83.58
182.116.83.58
182.116.83.58
This article from the "Zheng rongfeng" blog, please be sure to keep this source http://morgan363.blog.51cto.com/606286/1555135
[Instance] Regular Expressions use grep and sed to process log Content and obtain the required content