4

What is the meaning of the following command:

cut -d" " -f1

I found out what cut -d" " means: removing spaces, right?

but what means this -f1?

user97250
  • 61
  • 1
  • 1
  • 3
  • 6
    Try man cut... – eyoung100 Jan 06 '15 at 20:14
  • 3
    Note that -d" " does not mean removing spaces. – mattdm Jan 06 '15 at 23:22
  • ... but defining fields separated by a certain character. To give another example, -d\! would look for ! per line and from each ! starting, cut would define a new field. Also note the important - which can be used for field names: -f2- will mean "from field #2 to end of line", which can be invaluable when amount of fields per line is expected to vary. – syntaxerror Jan 06 '15 at 23:54

1 Answers1

8

cut cuts/splits lines on the delimeter (specified by -d) and then selects certain fields from those cut up lines. Which fields is specified by -f (counting starts at 1, not at 0)

If you would have a file xyz with contents:

1 2 3
4
5 6

then

cut -d' ' -f1 xyz

would give you:

1
4
5

(even if there is no space at all on the line with just the 4)

All of this and e.g. that -s suppresses lines that do not have the cut character can be found in the man page for cut (man cut)

Anthon
  • 79,293