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]: [email protected])

... 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]: [email protected]|
Oct  3 10:29:14 125388-web2 qmail-local-handlers[22908]: [email protected]|
Oct  3 10:29:30 125388-web2 qmail-local-handlers[23017]: [email protected]|
Oct  3 10:30:58 125388-web2 qmail-local-handlers[23815]: [email protected]|
Oct  3 10:31:04 125388-web2 qmail-local-handlers[23861]: [email protected]|
Oct  3 12:06:52 125388-web2 qmail-local-handlers[30174]: [email protected]|
Oct  3 12:07:03 125388-web2 qmail-local-handlers[30240]: [email protected]|
Oct  3 12:19:05 125388-web2 qmail-local-handlers[3243]: [email protected]|

2 Answers 2

0

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

sed "s/.*\[\([0-9]\+\)\].*/\1/" logfile
4

Have you tried:

cut -d '[' -f 2 LOGFILE | cut -d ']' -f 1
1
  • that was short :)
    – warren
    Oct 7, 2009 at 4:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .