- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
sudeshna_dash
New Member
12-14-2017
02:19 AM
I am trying to extract a value and add it to every events of that sourcetype.
source="c:\\splunk monitors\\log(2).txt" | eval ServiceTag = [search source="c:\\splunk monitors\\log(2).txt" | head 1 | rex field=_raw "^[^\[\n]*\[(?P<SvcTag>[^\]]+)" | eval tag = SvcTag | return $tag ]
Here $tag returns 5Q4RZH2 which is a string and thus, it is not able to get stored in ServiceTag variable of eval.
If the tag would have returned some number such as "123" then it is able to store the same.
E.g.
source="c:\\splunk monitors\\log(2).txt" | eval ServiceTag = [search source="c:\\splunk monitors\\log(2).txt" | head 1 | rex field=_raw "^[^\[\n]*\[(?P<SvcTag>[^\]]+)" | eval tag = "123"| return $tag ]
In this scenario, ServiceTag has the value 123
Hence, it is getting difficult to store a string.
Can someone please solve?
1 Solution
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

HiroshiSatoh
Champion
12-14-2017
03:10 AM
Try this!
| eval tag = SvcTag | return $tag ]
↓
| eval tag = "\""+SvcTag+"\"" | return $tag ]
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

niketn
Legend
12-14-2017
03:24 AM
@sudeshna_dash, are you doing it in a dashboard? Can you add some sample data and post the example above using code button?
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
| makeresults | eval message= "Happy Splunking!!!"
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

HiroshiSatoh
Champion
12-14-2017
03:10 AM
Try this!
| eval tag = SvcTag | return $tag ]
↓
| eval tag = "\""+SvcTag+"\"" | return $tag ]
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
sudeshna_dash
New Member
12-15-2017
06:38 AM
Thanks a lot @HiroshiSatoh, this worked. I am grateful to u
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

mayurr98
Super Champion
12-14-2017
02:31 AM
Try
source="c:\\splunk monitors\\log(2).txt" | eval ServiceTag =case( [search source="c:\\splunk monitors\\log(2).txt" | head 1 | rex field=_raw "^[^\[\n]*\[(?P<SvcTag>[^\]]+)" | eval tag = SvcTag | return 10000 tag ],tag)
Let me know if this helps!
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
sudeshna_dash
New Member
12-14-2017
02:41 AM
Thanks @mayurr98 but this doesn't solve the problem
