#!/usr/bin/env awk
#
# Splits compound values and provides easy access to the subvalues.
# If num is omitted or 0, val is split into 'osep' separated columns.
# If num > 0, returns the num repetition.
# If num < 0, returns the num item from the end, e.g., -1 for last element.
# Multiple 'num' can be specified, e.g., "1;-1;2"
# Output separator 'osep' defaults to OFS
#
# Dependencies:
#   - None
#
# See Also:
#   - splitr
#   - t2split
#
# Examples:
#   - tawk '{ print splitc($srcMac_dstMac_numP, 2) }' file.txt
#   - tawk 'splitc($srcMac_dstMac_numP, 2) == "00:11:22:33:44:55" { print splitc($srcMac_dstMac_numP) }' file.txt
#   - tawk 'flow(2) { print splitc(splitr($L2L3L4Pl_Iat, 0, "\n")) }' file.txt
#   - tawk '{ split($Ps_Iat_Cnt_PsCnt_IatCnt, x, ";"); for (i in x) { print splitc(x[i], "2;3") } }' file.txt
#   - tawk '{ print splitc($srcMac_dstMac_numP, "1;2") }' file.txt

@include "t2split"

function splitc(val, num, osep) {
    return t2split(val, "_", num, osep)
}
