If I understood well for each input line all the (value)
fields has to be parsed and then all value
fields have to be skipped. I assume that all field ends with a comma char except the last one.
Here is my suggestion:
awk ' { delete a; s="" # Reset tmp values
#Search for all (...) fields
for(i=1;i<=NF;++i) {
if (match($i,/^\((.*)\),?$/)) {
num=$i; gsub(/(^\(|\),?$)/,"",num);
a[num","]=1;
}
}
#Skip all fields contained by a hash
for(i=1;i<=NF;++i) if(!(($i)(i<NF?"":",") in a)) s=s FS $i;
# Trim leading field separator and trailing comma (if exists)
gsub("(^"FS"|,$)","",s);
print s;
}' inputfile
Input file:
444, 1234, (1234), 3453534, 43534543
444, (1235), 1235, 1235, 1234, 3453534, 43534543
444, (1235), 1235, 1235, 1234, 3453534, 43534543, (1234)
444, 1235, 1235, 1235, 1234, 3453534, 43534543
444, 1234, (1234)
444, (1235), 1235
Output:
444, (1234), 3453534, 43534543
444, (1235), 1234, 3453534, 43534543
444, (1235), 3453534, 43534543, (1234)
444, 1235, 1235, 1235, 1234, 3453534, 43534543
444, (1234)
444, (1235)
I hope this helps a bit!