Using cut is not a recommended command to do the job, as it can be done on a single line using awk.
For instance,
data='field1;field2;field3;field4;' echo $data|awk -F';' '{print NF}'
In fact, 5 will return above, because there is a semicolon in the data at the end, so linux awk assumes the last field is empty.
But if it is expected to be so, then you can use the command below to subtract 1.
echo $data|awk -F';' '{print NF-1}'
Explanation: The -F option in awk is for a separator, in which case a semicolon (enclosed in a single quotation mark) NF means the number of fields.
source share