Splunk Search

REGEX help on field extraction?

remy06
Contributor

Hi,

I am trying to extract fields from events and here are the sample events:

AUD_Proc user1 OK Thu Sep 16 15:09:45 2010 audit
pid: 0 cmd: 4

TCB_Exec user1 OK Thu Sep 16 15:09:45 2010 audit
filename: /usr/sbin/audit

CRON_Start root OK Tue Oct 05 23:40:00 2010 cron

S_PASSWD_READ root OK Tue Oct 05 23:40:00 2010 java

I am tring to extract the "login" field (user1,root) but the generated pattern doesn't match all values.

For example,if i selected user1 and root as the example values,the pattern generated only captures event for TCB_Exec,and not other events like AUD_Proc,CRON_Start & S_PASSWD_READ.

Tags (2)
0 Karma
1 Solution

Genti
Splunk Employee
Splunk Employee

yes, something like:

[yoursourcetype]
EXTRACT-loginfield = ^\S+\s+(?<login>\S+)
EXTRACT-Status = ^\S+\s+\S+\s+(?<status>\S+)

..etc..

props.conf.spec for more info

View solution in original post

0 Karma

Genti
Splunk Employee
Splunk Employee

yes, something like:

[yoursourcetype]
EXTRACT-loginfield = ^\S+\s+(?<login>\S+)
EXTRACT-Status = ^\S+\s+\S+\s+(?<status>\S+)

..etc..

props.conf.spec for more info

0 Karma

remy06
Contributor

I see..thanks it works fine.

0 Karma

remy06
Contributor

thanks for the prompt reply.

Do I specify the commands you've provided in props.conf?

Here is a list of examples where it contains 5 columns:
(eg. event-FS_CHdir, login-user3, status-OK, time, command - tsm,su)etc

I'm trying to extract these fields for the 5 columns.

FS_Chdir user3 OK Tue Oct 26 11:10:49 2004 tsm
change current directory to: /home/user3

S_ENVIRON_WRITE user3 FAIL Tue Oct 26 11:10:49 2004 tsm
audit object write event detected /etc/security/environ

S_PASSWD_READ user3 OK Tue Oct 26 11:10:50 2004 su
audit object read event detected /etc/security/passwd

S_PASSWD_READ user3 OK Tue Oct 26 11:10:50 2004 su
audit object read event detected /etc/security/passwd

USER_SU user3 OK Tue Oct 26 11:10:53 2004 su
root

AUD_Proc user1 OK Thu Sep 16 15:09:45 2010 audit
pid: 0 cmd: 4

TCB_Exec user1 OK Thu Sep 16 15:09:45 2010 audit
filename: /usr/sbin/audit

CRON_Start root OK Tue Oct 05 23:40:00 2010 cron

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

I would use:

REGEX = ^\S+\s+(?<fieldname>\S+)
0 Karma

Genti
Splunk Employee
Splunk Employee

i think something like this should work for you:

REGEX = ^\w+ (\w+)
Yourfield  = $1

If you can send a bigger log file i can be a bit more sure, but using a regex tester this works ok for me.

Hope this helps

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...

Upgrade Prep for 10.4, Network Observability Deep Dives, and More from Splunk Lantern

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Splunk Developer Day announcements: AI agents, MCP tools, Forecasting, and Custom ...

Splunk Developer Day was packed with product and platform updates for developers building in the AI ...