5.4 table, rename, fields, dedup, and sort
Key Takeaways
- fields keeps or removes fields in the pipeline; it does not replace base-search event filters like status=500.
- table displays specified fields as columns in listed order for a tabular view.
- rename old AS new changes field names in results; downstream commands must use the new names.
- dedup removes duplicate events for specified field keys, optionally keeping N events per value.
- sort orders results ascending/descending and can limit output with sort N -field.
5.4 table, rename, fields, dedup, and sort
Blueprint objective 4.4 explicitly lists five commands Users must be able to apply: table, rename, fields, dedup, and sort. These commands usually appear after a selective base search. They do not replace index= or field=value filters; they organize, reduce, and present the events you already retrieved.
Command Map at a Glance
| Command | Primary job | Typical placement |
|---|---|---|
fields | Keep or remove fields from results | Early after search to reduce clutter/payload |
table | Retain listed fields and show results as a table | When you want a column-oriented view |
rename | Change field names (often for readability) | Before final presentation or downstream references |
dedup | Remove duplicate events for specified field keys | After filtering, often before table/sort |
sort | Order results by one or more fields | Usually near the end |
1) fields — Keep or Remove Fields
Purpose
fields controls which fields remain in the result set. It is about field selection, not about choosing which events match (that is what the base search/search command does).
Syntax patterns
Keep only certain fields:
... | fields host, status, clientip
Remove fields:
... | fields - useragent, referer
Wildcard removals/keeps are commonly taught in Splunk training forms such as:
... | fields - _*
(Use internal-field removals carefully; some commands expect internal fields like _time.)
Examples
index=web sourcetype=access_combined status=500
| fields _time, host, clientip, status, uri_path
index=security action=failed
| fields - punct, date_*
Exam notes
fieldshelps readability and can improve efficiency by discarding unneeded field data before later stages.fieldsis not a substitute forstatus=500in the base search.- A brief contrast:
where/evalcan build conditional logic later, but User objective 4.4 is testingfieldsfield inclusion/exclusion—not eval expressions.
2) table — Display Specific Columns
Purpose
table returns a table of the specified fields. Column order follows the order you list. Rows are the events/results flowing into the command.
Syntax
... | table <field1>, <field2>, <field3>, ...
Examples
index=web sourcetype=access_combined status=5*
| table _time, host, clientip, status, uri_path
index=security sourcetype=linux_secure action=failed
| table _time, user, src, host
| sort - _time
table vs fields
| Topic | fields | table |
|---|---|---|
| Main intent | Include/exclude fields in the pipeline | Present a table of listed fields |
| Output tab tendency | May still be event-oriented depending on context | Statistics/table-oriented presentation |
| Column order | Not primarily a display-ordering tool | Explicitly uses argument order as columns |
| Event filter? | No | No |
In many User workflows you may see either command used to narrow columns; for exam wording, if the question says display as a table with specific columns, prefer table.
3) rename — Rename Fields
Purpose
rename changes field names so headers are clearer in reports/tables or so names match a preferred label.
Syntax
... | rename <old_field> AS <new_field>
Multiple renames:
... | rename clientip AS src_ip, status AS http_status
Wildcards can rename groups of fields in more advanced patterns; for User focus, master the AS form first.
Examples
index=web sourcetype=access_combined status=500
| stats count BY clientip
| rename clientip AS src_ip, count AS error_count
| table src_ip, error_count
| sort - error_count
index=security action=failed
| table _time, user, host
| rename user AS username, host AS device
Exam notes
- After renaming, downstream commands must use the new names.
- Renaming does not change underlying stored index data; it changes names in the search result pipeline.
- Quotes may be needed for new names with spaces:
rename count AS "Error Count".
4) dedup — Remove Duplicates
Purpose
dedup removes subsequent duplicate events based on one or more specified fields, keeping the first event(s) for each unique field-value combination in the incoming order.
Because Splunk event searches typically return newest-first, “first retained” often means the most recent event per key unless sorting changed order earlier.
Syntax
... | dedup <field>
... | dedup <field1>, <field2>
... | dedup <N> <field>
Examples
Keep the newest event per user (given default reverse-time order):
index=vpn action=login
| dedup user
| table _time, user, src_ip
Dedup on a combination of fields:
index=security action=failed
| dedup user, src
| table _time, user, src, host
Keep two events per client IP:
index=web status=500
| dedup 2 clientip
| table _time, clientip, status, uri_path
Useful options (awareness level)
| Option | Meaning |
|---|---|
consecutive=true | Only remove duplicates that are adjacent |
keepempty=true/false | How to treat events missing the dedup field |
For most User exam items, knowing that dedup removes duplicates for listed fields and that an optional count keeps N per value is enough.
5) sort — Order Results
Purpose
sort orders results by one or more fields ascending or descending.
Syntax
... | sort <field>
... | sort -<field>
... | sort <field1>, -<field2>
... | sort <limit> -<field>
- Ascending:
sort statusorsort +status - Descending:
sort -status - Limit while sorting:
sort 10 -count
Examples
index=web sourcetype=access_combined status=500
| stats count BY host
| sort - count
index=web sourcetype=access_combined
| table _time, status, clientip, bytes
| sort status, - bytes
index=security action=failed
| stats count BY user
| sort 5 - count
Exam notes
- Default direction is ascending if not marked.
- Sort after aggregation when you need top talkers by count.
- Sorting huge raw event sets without limits can be expensive—filter/aggregate first when possible.
Putting All Five Together
Example A — Clean investigation table
index=web sourcetype=access_combined status=5*
| fields _time, host, clientip, status, uri_path, useragent
| dedup clientip
| rename clientip AS src_ip
| table _time, host, src_ip, status, uri_path
| sort - _time
Stage reading:
- Retrieve server-error web events.
- Keep relevant fields.
- One row per client IP.
- Rename for clarity.
- Display columns.
- Newest first.
Example B — Ranked summary prep (with stats awareness)
stats is Domain 5, but Users often combine 4.4 commands around it:
index=security action=failed
| stats count BY user
| rename count AS failures
| table user, failures
| sort 10 - failures
Here rename, table, and sort finalize a ranked failures list.
Example C — fields vs table choice
If the question is “remove unnecessary fields but continue processing events,” lean fields.
If the question is “show only these columns in a table,” lean table.
Decision Guide
| Goal | Prefer |
|---|---|
| Drop noisy fields early | fields - ... |
| Keep only needed fields | fields a, b, c or table a, b, c |
| Explicit tabular columns/order | table |
| Friendlier header names | rename old AS new |
| Unique entities (latest login per user) | dedup user |
| Ranked / chronological order | sort - field |
| Top N after counts | sort N - count |
Common Mistakes Across the Five Commands
| Mistake | Fix |
|---|---|
Using fields/table to filter event values | Use status=500 in the search stage |
| Sorting before narrowing millions of raw events | Filter/aggregate first; consider sort N |
Referencing old names after rename | Use the new names downstream |
Expecting dedup to pick “best” event by score | It keeps first in current order for the key |
Confusing dedup with sort | Distinct jobs: uniqueness vs order |
| Forgetting commas/AS syntax | Follow rename x AS y, table a, b, fields a, b |
Objective 4.4 Study Drill
For each command, practice until you can write one correct pipeline from memory:
fieldskeep listfieldsremove listtablethree columnsrenamewithASdedupone field and two fieldssortdescending with and without a numeric limit
If you can combine all five in one coherent search and explain each stage left to right, you have closed Domain 4.0’s command requirement for the Splunk Core Certified User exam.
Which command is the best fit when you want to display only _time, user, and status as columns in a table?
Which SPL snippet correctly renames clientip to src_ip?
You want the most recent failed login event per user, then newest-first output. Assuming default newest-first event order into dedup, which pipeline best fits?