My query works from Splunk Web UI and returns field values of
Source in a
table form, but it doesn't work from the CLI.
Splunk web returns
Source ========== stock funds
Splunk CLI returns output EMPTY
Splunk CLI doesn't returns the field values with the table command.
splunk search "index=apps sourcetype=weblogs | rex field=_raw \'Source:\s(?<Source>.*)\' | search Source | dedup Source | table Source" user admin password changeme
I have tried with
fields command instead of
splunk search "index=apps sourcetype=weblogs | rex field=_raw \'Source:\s(?<Source>.*)\' | search Source | dedup Source | eval chicken=Source | fields chicken" user admin password changeme
but still it output empty values
But it works well in web search results
Is there any other way to display the field values from command interface ?
Trying to back-pedal from the example you gave from the CLI, I still think your issue is related to shell quoting. Going back to the updates I gave to your other question, https://answers.splunk.com/answers/449193/how-to-run-rex-commands-from-cli-mode.html#answer-450021 ... using
set -x in the shell prompt helps you see better how shell expansion and quoting rules are affecting what is passed on to Splunk.
Given what you show above, your most likely to be successful CLI command is probably:
splunk search 'index=apps sourcetype=weblogs | rex field=_raw "Source:\s(?<Source>.*)" | search Source | dedup Source | table Source'
We wrap the whole SPL command in single quotes
' because that is the environment where the shell does the LEAST amount of interpretation and replacement. From the
bash man page:
Enclosing characters in single quotes preserves the literal value ofeach character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.
It doesn't help me in any way. Moreover, if I keep
" double quote at REX it throws me an error, and
\" doesn't work for REX anyway. And I am using windows machine cmd prompt, shell and bash don't apt to this scenario ?
It helps you plenty. If you are running a Splunk CLI search via the Windows CMD prompt, then you need to understand the quoting rules IT uses. It's the same thing, only different. When you're using a command line shell to run a command - regardless of what the command line shell is - you are subject to how IT interprets and quotes input before it passes it along to the child process it is starting on your behalf.
If you are not using CMD, but using PowerShell instead - it may have different quoting rules that you have to account for.
A quick google search of "windows command prompt quoting rules" brings these resources:
Maybe Your search should start with the search command?
splunk search "search ..."
Also you might want some time modifiers.