cut Linux Command
Extracts specific columns/fields from each line of a file.
What does cut do?
Extracts specific columns/fields from each line of a file.
Syntax
cut [options] filePractical example
cut -d':' -f1 /etc/passwdQuestions about cut
How do I extract specific columns with cut?
Use `cut -f1,3 file` to extract the first and third columns. Fields are separated by tab by default.
How do I set a custom delimiter?
Use `cut -d':' -f1 file` to use colon as the delimiter. Use `-d','` for comma, `-d' '` for space, etc.
How do I extract the first 5 characters of each line?
Use `cut -c1-5 file` to extract characters 1 through 5 from each line. The `-c` flag works with character positions.
How do I extract everything except a field?
Use `cut -f2 --complement file` to exclude the second field. The `--complement` flag inverts the field selection.
How do I cut by byte position?
Use `cut -b1-10 file` to extract the first 10 bytes of each line. This is useful for fixed-width data.
How do I extract usernames from /etc/passwd?
Use `cut -d':' -f1 /etc/passwd` to extract the first field (username) from the colon-delimited passwd file.
How do I cut with a space delimiter?
Use `cut -d' ' -f1,3 file` to use space as the delimiter. Be careful with multiple consecutive spaces.
How do I cut a CSV file?
Use `cut -d',' -f1,3 file.csv` to extract specific columns from a comma-separated values file.
Related Search Commands
uniqReports or filters out repeated lines in a sorted file.
trTranslates, deletes, or squeezes characters from standard input.
sortSorts lines of text files alphabetically or numerically.
xargsBuilds and executes command lines from standard input (useful with pipes).
sedStream editor for filtering and transforming text (find/replace, insert, delete).
findSearches for files and directories in a directory hierarchy by name, type, size, etc.