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?
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?
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)
man cut... – eyoung100 Jan 06 '15 at 20:14-d" "does not mean removing spaces. – mattdm Jan 06 '15 at 23:22-d\!would look for!per line and from each!starting,cutwould 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