I'm working with two similar, but not quite the same datasets and I want to create a table which displays data from either of the data sets in the same column. For example, one dataset has the field Source_Name and the other dataset has the field "Source Name". While I understand that spaces in field names is evil and should eb avoided, I have no control over the source data and am stuck working with what I have.
In the past, when trying to mash two datasets together like this, I have relied on strcat to give me a consistent field name to work with ala:
some search
| strcat FieldA FieldB FieldAB
Since only FieldA or FieldB will be populated, based on which dataset the record is from, I will get the appropriate entry in the resultant FieldAB. However, I've run into an issue this time as the spaces in the field name of one of my datasets is giving me trouble. I've tried:
| "Source Name" Source_Name SourceName
This treats the "Source Name" as a string literal.
| 'Source Name' Source_Name SourceName
This returns nothing for the case where 'Source Name' exists and 'Source_Name' does not.
| \"Source Name\" Source_Name SourceName
This returns nothing for the case where 'Source Name' exists and 'Source_Name' does not.
I do have a workaround where I rename the "Source Name" field to Source-Name and then do the strcat using that field. This works; but, I am wondering if there is a cleaner solution? Is there a way to reference a field name with a space in it, with the strcat command? Alternatively, is there just a better way of selectively displaying a different field, depending on which one exists in a dataset, specifically at search time?
I prefer the coalesce function for this scenario. It populates a field with the first non-null argument provided.
| eval Field = coalesce(FieldA, FieldB)
I prefer the coalesce function for this scenario. It populates a field with the first non-null argument provided.
| eval Field = coalesce(FieldA, FieldB)
That's perfect, thank you.
As a note for anyone else looking at this, for fields with spaces in the names, it's necessary to put the field name in single quotes. E.g.:
| eval SourceName=coalesce('Source Name', Source_Name)