unix - How to print number of particular columns in shell script? -


i have text file temp1 , has more 20 columns , has numerical values follows,

1,0,3,0,5........, 1,0,5,0,8........, 3,0,6,0,3........, 5,0,6,0,4........, ................., 

i want remove columns has total(sum) of 0 , need redirect remaining columns new file

ie : example above 2nd , 4th columns have total of 0 need remove 2nd , 4 th column , redirect separate file .

can 1 me pls?

$ cat file 1,0,3,0,5 1,0,5,0,8 3,0,6,0,3 5,0,6,0,4  $ awk -f tst.awk file 1,3,5 1,5,8 3,6,3 5,6,4  $ cat tst.awk begin{ fs="," } {     (j=1;j<=nf;j++) {         val[nr,j] = $j         sum[j] += val[nr,j]     } } end {     (i=1;i<=nr;i++) {         ofs = ""         (j=1;j<=nf;j++) {             if (sum[j]) {                 printf "%s%s",ofs,val[i,j]                 ofs = fs             }         }         print ""     } } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -