Hi,
Suppose if I have a file having data like this:
$ cat file.txt
A
B C
D
And, if I do a cut operation like this:
$ cut -d" " -f2 file.txt
The output is
A
C
D
This is the same for even if we try to get the field 3 with -f3 (assume line 2 has 3 fields : C E F).
The above output is applicable only when there is only one field per line.
But, if the file contains more then one field, like:
$ cat file.txt
A B
B C F
D E
Then, applying the command to fetch column 3 as:
$ cut -d" " -f3 file.txt
results in:
F
Why this behavior?
man man cut ("cut")
-f list The list following -f is a list of fields
assumed to be separated in the file by a
delimiter character \(see -d \); for instance,
-f1,7 copies the first and seventh field
only. Lines with no field delimiters will be
passed through intact \(useful for table sub-
headings\), unless -s is specified.
-n Do not split characters. When -b list and -n
are used together, list is adjusted so that
no multi-byte character is split.
-s Suppresses lines with no delimiter charac-
ters in case of -f option. Unless specified,
lines with no delimiters will be passed
through untouched.