2

I'm kinda a newbie to the whole Linux thing but I'm having a doozie of a time trying to figure out how to sift through a my qmail log files.

At this point, what I want to do is do a search that outputs just what is inside the square brackets after qmail-local-handlers. So, for example, taking the first line in my log snippet ...

(Oct  3 10:17:21 125388-web2 qmail-local-handlers[18145]: to=test@emailaddress.com)

... I would like for it to output 18145.

I'm not sure what commands I could run to get the result I'm looking for. Can anyone help?

Here is some sample data I'm using if it will help. Many thanks!!

Oct  3 10:17:21 125388-web2 qmail-local-handlers[18145]: to=test@emailaddress.com|
Oct  3 10:29:14 125388-web2 qmail-local-handlers[22908]: to=test@emailaddress.com|
Oct  3 10:29:30 125388-web2 qmail-local-handlers[23017]: to=test@emailaddress.com|
Oct  3 10:30:58 125388-web2 qmail-local-handlers[23815]: to=test@emailaddress.com|
Oct  3 10:31:04 125388-web2 qmail-local-handlers[23861]: to=test@emailaddress.com|
Oct  3 12:06:52 125388-web2 qmail-local-handlers[30174]: to=test@emailaddress.com|
Oct  3 12:07:03 125388-web2 qmail-local-handlers[30240]: to=test@emailaddress.com|
Oct  3 12:19:05 125388-web2 qmail-local-handlers[3243]: to=test@emailaddress.com|
Jeff Atwood
  • 13,104
  • 20
  • 75
  • 92
Marlon
  • 535
  • 2
  • 10
  • 14

2 Answers2

4

Have you tried:

cut -d '[' -f 2 LOGFILE | cut -d ']' -f 1
jomey
  • 312
  • 1
  • 3
0

This will grab the digits between the (first) pair of square brackets:

sed "s/.*\[\([0-9]\+\)\].*/\1/" logfile
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151