Cut (Unix) - Examples

Examples

Assuming a file named file containing the lines:

foo:bar:baz:qux:quux one:two:three:four:five:six:seven alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu the quick brown fox jumps over the lazy dog

To output the fourth through tenth characters of each line:

% cut -c 4-10 file

This gives the output:

:bar:ba :two:th ha:beta quick

To output the fifth field through the end of the line of each line using the colon character as the field delimiter:

% cut -d ":" -f 5- file

This gives the output:

quux five:six:seven epsilon:zeta:eta:teta:iota:kappa:lambda:mu the quick brown fox jumps over the lazy dog

(note that because the colon character is not found in the last line the entire line is shown)

Option -d specified a single character delimiter (in the example above it is a colon) which serves as field separator. option -f which specifies range of fields included in the output (here fields range from five till the end ). Option -d presuppose usage of option -f.

To output the third field of each line using space as the field delimiter:

% cut -d " " -f 3 file

This gives the output:

foo:bar:baz:qux:quux one:two:three:four:five:six:seven alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu brown

(Note that because the space character is not found in the first three lines these entire lines are shown.)

Read more about this topic:  Cut (Unix)

Famous quotes containing the word examples:

    In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.
    Michel de Montaigne (1533–1592)

    There are many examples of women that have excelled in learning, and even in war, but this is no reason we should bring ‘em all up to Latin and Greek or else military discipline, instead of needle-work and housewifry.
    Bernard Mandeville (1670–1733)

    No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.
    André Breton (1896–1966)