You could use something like this:
awk -v fl=<filed_list> 'BEGIN {
n = split(fl, t, " ")
for (i = 0; ++i <= n;)
fa[t[i]]
}
{
for (i = 0; ++i <= NF;)
if (!(i in fa))
printf "%s", ($i (i < NF ? OFS : ORS))
}'
Consider the following input:
zsh-4.3.14[t]% paste -sd\; < <(printf '%s\n' {1..10})
1;2;3;4;5;6;7;8;9;10
To remove the 3th field:
zsh-4.3.14[t]% paste -sd\; < <(printf '%s\n' {1..10}) |
pipe> awk -F\; -v fl=3 'BEGIN {
pipe quote> n = split(fl, t, " ")
pipe quote> for (i = 0; ++i <= n;)
pipe quote> fa[t[i]]
pipe quote> }
pipe quote> {
pipe quote> for (i = 0; ++i <= NF;)
pipe quote> if (!(i in fa))
pipe quote> printf "%s", ($i (i < NF ? OFS : ORS))
pipe quote> }' OFS=\;
1;2;4;5;6;7;8;9;10
To remove a set of fields:
zsh-4.3.14[t]% paste -sd\; < <(printf '%s\n' {1..10}) |
pipe> awk -F\; -v fl='7 4 3' 'BEGIN {
pipe quote> n = split(fl, t, " ")
pipe quote> for (i = 0; ++i <= n;)
pipe quote> fa[t[i]]
pipe quote> }
pipe quote> {
pipe quote> for (i = 0; ++i <= NF;)
pipe quote> if (!(i in fa))
pipe quote> printf "%s", ($i (i < NF ? OFS : ORS))
pipe quote> }' OFS=\;
1;2;5;6;8;9;10
Let me know how the output should look like if you remove the last filed (with or without the trailing FS).
Consider that with a single character field separator and for simple tasks cut could be sufficient:
zsh-4.3.14[t]% paste -sd\; < <(printf '%s\n' {1..10}) | cut -d\; -f 1-2,4-
1;2;4;5;6;7;8;9;10
zsh-4.3.14[t]% paste -sd\; < <(printf '%s\n' {1..10}) | cut -d\; -f 1-2,5-6,8-
1;2;5;6;8;9;10
[Edit: following the comments here]
Given the sample input:
3;03.2012;7228;0;1;3;1;3;4;3;1;3;4;3;2;0;4;4;1;1;4;2;1;1;1;1;1;1;1;1;1;1;1;1;0;0;0;1;1;3;0;3;1;3;0;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;
3;03.2012;7229;0;2;2;0;5;5;4;4;5;5;4;4;2;5;5;0;0;3;3;0;0;5;6;0;0;0;0;0;2;2;1;2;1;2;2;2;4;3;4;1;5;4;2;0;0;0;0;0;0;0;0;0;0;4;4;4;4;4;0;0;0;0;0;0;0;
3;03.2012;7230;0;2;2;2;4;3;4;4;4;3;3;3;2;4;6;1;1;1;6;5;1;6;6;1;1;1;1;1;2;2;1;2;2;0;2;2;3;4;2;1;4;3;2;0;0;0;0;0;0;0;0;0;0;4;3;3;4;4;0;0;0;0;0;0;0;
3;03.2012;7231;0;1;3;1;4;4;3;3;4;4;4;4;2;5;5;1;1;4;6;5;1;4;1;1;1;1;1;5;2;1;1;2;0;0;1;2;4;4;3;1;4;3;2;0;0;0;0;0;0;0;0;0;0;4;4;4;4;3;0;0;0;0;0;0;0;
and the following awk script:
zsh-4.3.14[t]% cat s.awk
BEGIN {
n = split(fl, t, " ")
for (i = 0; ++i <= n;)
fa[t[i]]
}
{
for (i = 0; ++i <= NF;)
if (!(i in fa))
printf "%s", ($i (i < NF ? OFS : ORS))
}
With this command:
zsh-4.3.14[t]% awk -F\; -v fl=3 -f s.awk OFS=\; infile > outfile
... I get the following output:
zsh-4.3.14[t]% cat outfile
3;03.2012;0;1;3;1;3;4;3;1;3;4;3;2;0;4;4;1;1;4;2;1;1;1;1;1;1;1;1;1;1;1;1;0;0;0;1;1;3;0;3;1;3;0;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;
3;03.2012;0;2;2;0;5;5;4;4;5;5;4;4;2;5;5;0;0;3;3;0;0;5;6;0;0;0;0;0;2;2;1;2;1;2;2;2;4;3;4;1;5;4;2;0;0;0;0;0;0;0;0;0;0;4;4;4;4;4;0;0;0;0;0;0;0;
3;03.2012;0;2;2;2;4;3;4;4;4;3;3;3;2;4;6;1;1;1;6;5;1;6;6;1;1;1;1;1;2;2;1;2;2;0;2;2;3;4;2;1;4;3;2;0;0;0;0;0;0;0;0;0;0;4;3;3;4;4;0;0;0;0;0;0;0;
3;03.2012;0;1;3;1;4;4;3;3;4;4;4;4;2;5;5;1;1;4;6;5;1;4;1;1;1;1;1;5;2;1;1;2;0;0;1;2;4;4;3;1;4;3;2;0;0;0;0;0;0;0;0;0;0;4;4;4;4;3;0;0;0;0;0;0;0;
If I understand the requirement correctly, the output is correct.
To remove the fields from 1 to 5:
zsh-4.3.14[t]% awk -F\; -v fl='1 2 3 4 5' -f s.awk OFS=\; infile > outfile
zsh-4.3.14[t]% cat outfile
3;1;3;4;3;1;3;4;3;2;0;4;4;1;1;4;2;1;1;1;1;1;1;1;1;1;1;1;1;0;0;0;1;1;3;0;3;1;3;0;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;
2;0;5;5;4;4;5;5;4;4;2;5;5;0;0;3;3;0;0;5;6;0;0;0;0;0;2;2;1;2;1;2;2;2;4;3;4;1;5;4;2;0;0;0;0;0;0;0;0;0;0;4;4;4;4;4;0;0;0;0;0;0;0;
2;2;4;3;4;4;4;3;3;3;2;4;6;1;1;1;6;5;1;6;6;1;1;1;1;1;2;2;1;2;2;0;2;2;3;4;2;1;4;3;2;0;0;0;0;0;0;0;0;0;0;4;3;3;4;4;0;0;0;0;0;0;0;
3;1;4;4;3;3;4;4;4;4;2;5;5;1;1;4;6;5;1;4;1;1;1;1;1;5;2;1;1;2;0;0;1;2;4;4;3;1;4;3;2;0;0;0;0;0;0;0;0;0;0;4;4;4;4;3;0;0;0;0;0;0;0;
Am I missing something?