In the Unix/Linux cut command, which option is used to specify the field delimiter character for splitting input lines into fields?

Difficulty: Easy

Correct Answer: -d option

Explanation:


Introduction / Context:
When extracting fields with cut, the utility must know how to split each line. The delimiter can be a comma, tab, colon, or any single character. Choosing and declaring the correct delimiter is essential for accurate column extraction.


Given Data / Assumptions:

  • Your input is consistently delimited (for example, CSV with commas).
  • You know which fields (-f) you want.
  • You need to set the split character explicitly if it is not a tab.


Concept / Approach:
The -d option to cut sets the field delimiter. For example, -d ',' uses a comma; -d ':' uses a colon. Without -d, cut defaults to tab for field mode. Pair -d with -f to pick specific fields. Other letters shown here (-a, -r, -x) are not valid delimiter switches for cut.


Step-by-Step Solution:

Use comma as delimiter: cut -d ',' -f 2,4 data.csvUse colon for /etc/passwd style: cut -d ':' -f 1,7 /etc/passwdDefault tab delimiter: cut -f 1-3 data.tsvChain with sort/uniq for further processing.


Verification / Alternative check:
Print a sample line and visually count separators to ensure that the -d character matches the actual data; otherwise you will see empty or misaligned fields in output.


Why Other Options Are Wrong:

  • -a / -r / -x: Not the correct switch for specifying a delimiter in cut.
  • None of the above: Incorrect because -d is the proper delimiter option.


Common Pitfalls:
Using multi-character delimiters (unsupported by cut) or forgetting to quote special shell characters such as '|' or '*' if used as delimiters in unusual cases.


Final Answer:
-d option

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion