Cut counting consecutive delimiters as fields

When cut encounters consecutive delimiters it seems to count each instance as a field, at least with spaces. Is this typical behavior for any delimiter?

#:~$ ifconfig eth0 | grep HWaddr
eth0      Link encap:Ethernet  HWaddr 94:de:80:a7:6d:e1  
#:~$ ifconfig eth0 | grep HWaddr | cut -d " " -f 11
94:de:80:a7:6d:e1

Yes, with cut every occurrence of the delimiter separates a field.

--
The default delimiter in awk does not. Try:

ifconfig eth0 | awk '/HWaddr/{print $5}'
1 Like

As a side note, if you want to know the mac assigned to an interface, in a Linux system just read it from /sys :

cat /sys/class/net/eth0/address

Much faster.

1 Like

Thank you. Awk's default behavior is easy to grasp, but I am trying to understand this cut example in the book. Just trying to understand the counting principle at work here. It just seems a field pops out of nowhere. for example:

word1 word2
  • one delimiter, two fields
word1  word2
  • two consecutive delimiters in a row, 4 fields
word1   word2
  • 3 consecutive delimiters in a row, 5 fields

Correct? In the first example the delimiter is not counted as a field, but with consecutive occurrences we simply count each one as an occurrence of a field.

No, there is always one more fields than delimiters.
Between consecutive delimiters there is an empty field.

2 Likes

Got it. Thank you all for the help. Marking as solved.

BTW some versions of cut has -F option that folds adjacent delimiters into one