# Copy part of a field into new field

**URL:** <https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456>\
**Category:** Logstash\
**Created:** [December 6, 2017, 5:04am UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456 "2017-12-06T05:04:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathurin68](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@mathurin68](https://discuss.elastic.co/u/mathurin68)\
**Post date:** [December 6, 2017, 5:04am UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/1 "2017-12-06T05:04:24Z")

</div>

Alright, I've got another question is it possible to copy part of one field into another? I.E.  
I have  
NewProcessName - C:\Windows\SysWOW64\dllhost.exe  
I want to move everything after last backslash to new field  
SuspProc - dllhost.exe

I have this

filter {  
if [event\_id] == 4688 {  
mutate {  
copy =\> {"[event\_data][NewProcessName]" =\> "[event\_data][SuspProc]" }  
}  
}  
}

and I have the regex that will pull what is after the last back slash -  
([^\]+)$  
and regex that will pull everything before -  
/^(.\*[\/])/

is there a way to do this with copy? Or would I need to try and use gsub to erase everything before the last backslash?

Thanks!

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 6, 2017, 6:31am UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/2 "2017-12-06T06:31:03Z")

</div>

Use a grok filter. Examples have been posted in the past, though perhaps tailored to paths with forward slashes rather than backslashes.

---

<div class="post-metadata">

**Author:** ![mathurin68](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@mathurin68](https://discuss.elastic.co/u/mathurin68)\
**Post date:** [December 6, 2017, 4:25pm UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/3 "2017-12-06T16:25:03Z")

</div>

Hmmm, so why can't I use this?

filter {  
grok {  
match =\> ["[event\_data][NewProcessName]", "(?\<[event\_data][SuspProc]\>([^\/]+$))" ]  
}  
}

NewProcessName - C:\Windows\SysWOW64\dllhost.exe  
to create the new field and add what's after the last backslash?  
SuspProc - dllhost.exe

this gives me the pipleine terminated error.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [December 6, 2017, 4:54pm UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/4 "2017-12-06T16:54:39Z")

</div>

Because the syntax is grok { match =\> { "field" =\> "pattern" }} not grok { match =\> ["field" , "pattern"]}

---

<div class="post-metadata">

**Author:** ![mathurin68](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@mathurin68](https://discuss.elastic.co/u/mathurin68)\
**Post date:** [December 7, 2017, 5:00am UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/5 "2017-12-07T05:00:29Z")

</div>

This is torture, nothing seems to be working...

```
filter {
grok {
match => ["[event_data][NewProcessName]", "/(?<SuspProc>([^\\]+)$)"]
}
}
*no pipeline errors but no new SuspProc field

filter {
grok {
match => "[event_data][NewProcessName]", "/(?<SuspProc>([^\\]+)$)"
}
}
*pipeline errors and no new SuspProc field

filter {
grok {
match => {"[event_data][NewProcessName]", "/(?<SuspProc>([^\\]+)$)"}
}
}
*pipeline errors and no new SuspProc field

filter {
grok {
match => ["[event_data.NewProcessName]", "/(?<SuspProc>([^\\]+)$)"]
}
}
*no pipeline errors but no new SuspProc field

filter {
grok {
match => ["[event_data.NewProcessName]" => "/(?<SuspProc>([^\\]+)$)"]
}
}
*pipeline errors and no new SuspProc field

filter {
grok {
match => ["event_data.NewProcessName" , "/(?<SuspProc>([^\\]+)$)"]
}
}
*no pipeline errors but no new SuspProc field

filter {
grok {
match => ["NewProcessName" , "/(?<SuspProc>([^\\]+)$)"]
}
}
*no pipeline errors but no new SuspProc field

```

event\_data.NewProcessName is in Discovery why can't I do this?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 7, 2017, 7:01am UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/6 "2017-12-07T07:01:41Z")

</div>

> Because the syntax is grok { match =\> { "field" =\> "pattern" }} not grok { match =\> ["field" , "pattern"]}

Actually, both syntaxes are fine.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 7, 2017, 7:02am UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/7 "2017-12-07T07:02:38Z")

</div>

Show us an example event. Use a `stdout { codec => rubydebug }` output.

---

<div class="post-metadata">

**Author:** ![mathurin68](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@mathurin68](https://discuss.elastic.co/u/mathurin68)\
**Post date:** [December 7, 2017, 3:18pm UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/8 "2017-12-07T15:18:03Z")

</div>

> [@magnusbaeck](#):
>
> stdout { codec =\> rubydebug }

filter {  
grok {  
match =\> ["[event\_data][NewProcessName]", "/(?([^\]+)$)"]  
}  
}

Here is syslog with above, I hope I didn't copy anything in there, I appreciate this @magnusbaeck....

Dec 7 09:58:23 elkstack logstash[31542]: "type" =\> "wineventlog",  
Dec 7 09:58:23 elkstack logstash[31542]: "opcode" =\> "Info",  
Dec 7 09:58:23 elkstack logstash[31542]: "version" =\> 1,  
Dec 7 09:58:23 elkstack logstash[31542]: "tags" =\> [  
Dec 7 09:58:23 elkstack logstash[31542]: [0] "beats\_input\_codec\_plain\_applied",  
Dec 7 09:58:23 elkstack logstash[31542]: [1] "\_grokparsefailure"  
Dec 7 09:58:23 elkstack logstash[31542]: ],  
Dec 7 09:58:23 elkstack logstash[31542]: "thread\_id" =\> 96,  
Dec 7 09:58:23 elkstack logstash[31542]: "@timestamp" =\> 2017-12-07T14:54:01.283Z,  
Dec 7 09:58:23 elkstack logstash[31542]: "event\_id" =\> 4688,  
Dec 7 09:58:23 elkstack logstash[31542]: "task" =\> "Process Creation",  
Dec 7 09:58:23 elkstack logstash[31542]: "provider\_guid" =\> "{54849625-5478-4994-A5BA-3E3B0328C30D}",  
Dec 7 09:58:23 elkstack logstash[31542]: "@version" =\> "1",  
Dec 7 09:58:23 elkstack logstash[31542]: "beat" =\> {  
Dec 7 09:58:23 elkstack logstash[31542]: "name" =\> "IBCESCWVPSECFEV",  
Dec 7 09:58:23 elkstack logstash[31542]: "hostname" =\> "IBCESCWVPSECFEV",  
Dec 7 09:58:23 elkstack logstash[31542]: "version" =\> "6.0.0"  
Dec 7 09:58:23 elkstack logstash[31542]: },  
Dec 7 09:58:23 elkstack logstash[31542]: "host" =\> "IBCESCWVPSECFEV",  
Dec 7 09:58:23 elkstack logstash[31542]: "source\_name" =\> "Microsoft-Windows-Security-Auditing"  
Dec 7 09:58:23 elkstack logstash[31542]: }  
Dec 7 09:58:23 elkstack logstash[31542]: {  
Dec 7 09:58:23 elkstack logstash[31542]: "computer\_name" =\> "XXXXXX",  
Dec 7 09:58:23 elkstack logstash[31542]: "process\_id" =\> 4,  
Dec 7 09:58:23 elkstack logstash[31542]: "keywords" =\> [  
Dec 7 09:58:23 elkstack logstash[31542]: [0] "Audit Success"  
Dec 7 09:58:23 elkstack logstash[31542]: ],  
Dec 7 09:58:23 elkstack logstash[31542]: "log\_name" =\> "Security",  
Dec 7 09:58:23 elkstack logstash[31542]: "level" =\> "Information",  
Dec 7 09:58:23 elkstack logstash[31542]: "record\_number" =\> "2889961",  
Dec 7 09:58:23 elkstack logstash[31542]: "event\_data" =\> {  
Dec 7 09:58:23 elkstack logstash[31542]: "SubjectUserName" =\> "XXXX",  
Dec 7 09:58:23 elkstack logstash[31542]: "CommandLine" =\> ""C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE" SCODEF:8968 CREDAT:3618026 /prefetch:2",  
Dec 7 09:58:23 elkstack logstash[31542]: "NewProcessId" =\> "0x22d4",  
Dec 7 09:58:23 elkstack logstash[31542]: "TokenElevationType" =\> "%%1936",  
Dec 7 09:58:23 elkstack logstash[31542]: "SubjectDomainName" =\> "XXX",  
Dec 7 09:58:23 elkstack logstash[31542]: "ProcessId" =\> "0x2308",  
Dec 7 09:58:23 elkstack logstash[31542]: "SubjectLogonId" =\> "0x32432f13",  
Dec 7 09:58:23 elkstack logstash[31542]: "NewProcessName" =\> "C:\Program Files (x86)\Internet Explorer\iexplore.exe",  
Dec 7 09:58:23 elkstack logstash[31542]: "SubjectUserSid" =\> "S-1-5-21-2907011200-4146745624-917563655-64722"  
Dec 7 09:58:23 elkstack logstash[31542]: },  
Dec 7 09:58:23 elkstack logstash[31542]: "message" =\> "A new process has been created.\n\nSubject:\n\tSecurity ID:\t\tS-1-5-21-2907011200-4146745624-917563655-64722\n\tAccount Name:\t\XXXXt\n\tAccount Domain:\t\tXXXX\n\tLogon ID:\t\t0x32432f13\n\nProcess Information:\n\tNew Process ID:\t\t0x22d4\n\tNew Process Name:\tC:\Program Files (x86)\Internet Explorer\iexplore.exe\n\tToken Elevation Type:\tTokenElevationTypeDefault (1)\n\tCreator Process ID:\t0x2308\n\tProcess Command Line:\t"C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE" SCODEF:8968 CREDAT:3618026 /prefetch:2\n\nToken Elevation Type indicates the type of token that was assigned to the new process in accordance with User Account Control policy.\n\nType 1 is a full token with no privileges removed or groups disabled. A full token is only used if User Account Control is disabled or if the user is the built-in Administrator account or a service account.\n\nType 2 is an elevated token with no privileges removed or groups disabled. An elevated token is used when User Account Control is enabled and the user chooses to start the program using Run as administrator. An elevated token is also used when an application is configured to always require administrative privilege or to always require maximum privilege, and the user is a member of the Administrators group.\n\nType 3 is a limited token with administrative privileges removed and administrative groups disabled. The limited token is used when User Account Control is enabled, the application does not require administrative privilege, and the user does not choose to start the program using Run as administrator.",

Is in Disover -  
t event\_data.NewProcessName C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

---

<div class="post-metadata">

**Author:** ![mathurin68](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@mathurin68](https://discuss.elastic.co/u/mathurin68)\
**Post date:** [December 7, 2017, 5:34pm UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/9 "2017-12-07T17:34:23Z")

</div>

Tried this one I found on google from back in 2013 -

filter {  
grok { match =\> ["NewProcessName", "([^\]+)${event\_data:SuspProc}" ] }  
}  
\*no pipeline errors but no SuspProc field either.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 7, 2017, 8:04pm UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/10 "2017-12-07T20:04:28Z")

</div>

Your expression starts with `/` but you don't have any forward slashes in your file paths. Try `\\` instead, or emitting it completely if that doesn't work.

---

<div class="post-metadata">

**Author:** ![mathurin68](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@mathurin68](https://discuss.elastic.co/u/mathurin68)\
**Post date:** [December 8, 2017, 4:41am UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/11 "2017-12-08T04:41:34Z")

</div>

Whew, I appreciate everyone's help with this... I finally just ended up doing this -

filter {  
if [event\_id] == 4688 {  
mutate {  
copy =\> {"[event\_data][NewProcessName]" =\> "[event\_data][SuspProc]" }  
}  
}  
}

filter {  
if [event\_id] == 4688 {  
mutate {  
gsub =\> ["[event\_data][SuspProc]", "^(.\*[\/])", "" ]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 5, 2018, 4:41am UTC](https://discuss.elastic.co/t/copy-part-of-a-field-into-new-field/110456/12 "2018-01-05T04:41:54Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
