I need to split a field in awk by a "+" character, but not if the character preceding it is a "?". I have put together a basic example of the idea below.
exampleString="Var1, Var2Pt1+Var2Pt2+Var2Pt?+3+Var2Pt4, Var3"
awkOutput=`awk '
BEGIN{FS=",";}
{NUM_PARTS=split($2,SUBFIELDS,"+");
for (i = 1; i<=NUM_PARTS; i++) {
print SUBFIELDS[i]","
}
}
' <<<"$exampleString"`
echo $awkOutput;
Current Output:
Var2Pt1, Var2Pt2, Var2Pt?, 3, Var2Pt4,
Desired Output:
Var2Pt1, Var2Pt2, Var2Pt+3, Var2Pt4,
Is there some way to deal with this using split, or is there another means of achieving this in an elegant manner? The need for this has arisen in part of a very large awk script - so the simpler the solution the better!
Thanks.
Just an update - I did not make explicit that the "?" is to be treated as an escape character in my original question - i.e. it is not desired on the output.