I'm encountering the following issue.
I need to remove columns within a file that contain a specific string in the header. The semi-colon are acting as column limit
Examples below
file 1
ADM_THO_CVL2000,ZO,AT;BS-CCI-BAL,ARA,EL;BS-TLI-MS,ARA,BG;
1;2;3;
4;5;6;
file 2
BS-CCI-BAL,ARA,EL;BS-TLI-MS,ARA,BG;ADM_THO_CVL2000,OZ,ES;BAG-AL,W,SE;
1;2;3;5;
4;5;6;7;
ADM_THO_CVL2000
is the specific string I need to remove. The results , once string and the subsequent columns are removed, are below:
BS-CCI-BAL,ARA,EL;BS-TLI-MS,ARA,BG;
2;3;
5;6;
BS-CCI-BAL,ARA,EL;BS-TLI-MS,ARA,BG;BAG-AL,W,SE;
1;2;5;
4;5;7;
I had a look on the internet.
awk
can do the job that but the results I'm having, are not the one that I expect. I'm giving you the code below:
awk '
FNR==1{
for(i=1;i<=NF;i++)
if ($i ~ str) {
h=(h)?h FS $i:$i
f=(f)?f FS i:i
}
print h
nf=split(f,fA,FS);next
}
{
for(i=1;i<=nf;i++)
printf("%s%c",$fA[i], (i==nf)?ORS:FS)
}' str=ADM_THO_CVL2000, 'FS=;' filename.csv
I'm all ears for any of your suggestions.
Cheers