When GNU cut selects fields, a line without the chosen delimiter is normally printed unchanged. That can put a whole warning message or comment into what you expected to be a column of values. Use -s, also called --only-delimited, to suppress lines that have no field separator. This is a filtering decision, not proof that the remaining records are valid.
The distinction matters when a quick terminal extraction becomes input to an inventory import or report. First inspect what the source actually contains. Do not overwrite the original while experimenting, and do not silently discard malformed records if they require investigation.
Reproduce the unexpected full line without creating files
This Bash example sends three known lines through cut. It uses a colon as the delimiter and asks for the second field. The middle line has no colon at all.
printf '%s\n' 'app:ready' 'maintenance note' 'db:paused' | cut -d ':' -f 2
The expected output is three lines: ready, maintenance note, and paused. The maintenance note is not a second field; it is the entire undelimited input line. This behaviour is documented for field selection and should not be treated as evidence of a corrupt installation.
Field numbering begins at one. The delimiter normally defaults to a tab, but the example explicitly selects a colon. Quotes protect the shell argument; they do not make cut understand a structured document format.
Suppress only the lines with no separator
Add the flag deliberately after deciding what those undelimited lines mean for your task:
printf '%s\n' 'app:ready' 'maintenance note' 'db:paused' | cut -s -d ':' -f 2
The expected output is now just ready and paused on separate lines. The note is omitted because its input line contains no colon. The command reads standard input and writes standard output; it does not edit a source file. For a real file, supply its quoted path after the options and keep the original untouched until you have reviewed the extraction.
Suppression can be appropriate when an agreed export format intentionally includes separator-free commentary. It is inappropriate when every line is supposed to be a complete record and an absent delimiter signals a failed upstream export. In that case, record or reject the anomaly rather than making it disappear from your evidence.
An empty value is different from a missing delimiter
A line can contain a colon and still have an empty second field. It can also contain more fields than you intended. This fixture distinguishes those cases:
printf '%s\n' 'app:' ':ready' 'db:paused:extra' 'comment' | cut -s -d ':' -f 2
The output begins with a blank line, then ready, then paused. The first record contains a separator but its selected value is empty. The last comment is suppressed. The extra third field is not rejected; cut simply selects field two. Therefore -s does not enforce a two-field schema, require nonempty values, validate allowed status names or identify duplicate application identifiers.
Before connecting this to an import, define how many fields are permitted, whether empty identifiers or values are allowed, and whether malformed input should abort the operation. Use a parser or explicit validation suited to that contract. Do not infer validity from cut’s successful completion alone.
Do not treat a comma delimiter as a CSV parser
Choosing a comma only changes the separator used by this field tool. It does not implement CSV quotation rules or preserve quoted commas and multiline records as logical fields. A simple-looking export can become unsafe as soon as a description contains punctuation or a line break. Use a CSV-aware parser for CSV rather than expanding a fragile chain of text commands.
Likewise, delimiter filtering and duplicate filtering solve different problems. If your next step uses uniq, remember that it compares adjacent lines. See why uniq misses repeated lines that are not adjacent before assuming the extraction has also produced unique values.
Review checklist and short answers
- Confirm the actual separator instead of guessing from visual spacing.
- Include separator-free, empty-field and extra-field cases in tests.
- Decide whether discarded lines are acceptable commentary or evidence of failure.
- Compare expected records with extracted output before feeding another tool.
- Keep originals and inspect diagnostics; avoid accidental input-file overwrite through shell redirection.
Does -s remove every bad row? No. It suppresses lines without separators, not every invalid record. Does a blank output line mean there was no delimiter? Not necessarily: a delimited input can have an empty selected field. Should I add sudo? Not for this demonstration. Permission problems require an appropriate access review, not automatic privilege escalation.
Source and safety
Source: the GNU Coreutils manual source, specifically the cut invocation section and its fields and only-delimited options. Check the local manual for your installed version. This tutorial is for educational purposes. Test carefully before using steps in production. The site owner is not responsible for misuse, damage, data loss or production issues.



