In AWK can i set up multiple delimiter in action , like below example
BEGIN { Actions}
{ACTION-1} # here delimiter will be comma ","
{ACTION-2} # here delimiter will be colon":"
{ACTION-1} # here delimiter will be space " "
END { Actions }
In AWK can i set up multiple delimiter in action , like below example
BEGIN { Actions}
{ACTION-1} # here delimiter will be comma ","
{ACTION-2} # here delimiter will be colon":"
{ACTION-1} # here delimiter will be space " "
END { Actions }
Not really, but what you can do instead is explicitly split the line you're looking at. That would be:
{ split($0, parts, ","); ACTION-1 }
{ split($0, parts, ":"); ACTION-2 }
{ split($0, parts, " "); ACTION-1 }
This way you get the values you're after, but they're accessible as parts[1], parts[2], ...
rather than $1, $2, ...
.
Yes you can:
BEGIN { Actions}
{FS=","; $0=$0; ACTION-1} # here delimiter will be comma ","
{FS=":"; $0=$0; ACTION-2} # here delimiter will be colon":"
{FS=" "; $0=$0; ACTION-1} # here delimiter will be space " "
END { Actions }
Assigning anything to $0
causes awk to re-do field splitting using the current value of FS
so the fact it had already split the record into fields before then is irrelevant.
Having said that - there's almost certainly a better approach to whatever it is you're trying to do.