I have a tab-separated file with multiple columns, the first three of which are chr,start, and end. Other columns contain different samples with a specific score. My primary goal here is to limit values to three decimal places for all samples.

grep -v 'NA' TestAllScore.tsv | head -n 10
chr start   end EE85756 EE85757 EE85770 EE85775
chr1    9900    10000   0.370534858784818   0.506262316364967   0.249866030926826   0.663009952219704
chr1    10000   10100   214.786706475599    313.545127935369    250.865495050533    335.980293287335
chr1    10100   10200   511.214593503454    684.63540583089 540.710090925652    713.895966052567
chr1    10200   10300   516.525593146036    630.296583874384    465.875214663067    545.822943164872
chr1    10300   10400   297.539491604209    396.572147819224    346.689117910971    339.295343048434
chr1    10400   10500   142.161874153775    272.537880309807    238.372193504192    255.093079116531
chr1    10500   10600   191.072475513371    295.150930440776    246.118040462924    277.635417492001
chr1    10600   10700   237.142309622283    345.102145655452    308.459615179167    306.310597925503
chr1    10700   10800   239.859565253372    270.512831044347    294.342184431801    272.497090362299

I used the script below to accomplish this, but it looks like the output is missing a header.

awk '{ for (i=4; i<=NF; ++i) $i=sprintf("%.3f", $i); print }' TestAllScore.tsv | sed 's/ /t/g' > TestAllScore2.tsv

grep -v '0.00' 11jHL.win.nucocc6.txt | head -n 10
chr1    11000   11100   177.486 211.955 240.996 249.955
chr1    11100   11200   136.480 218.874 242.620 236.529
chr1    11200   11300   106.714 251.444 252.240 225.921
chr1    11300   11400   172.422 274.900 305.336 211.997
chr1    11400   11500   178.104 301.732 303.087 196.085
chr1    11500   11600   192.431 272.875 252.864 219.954
chr1    11600   11700   256.287 271.863 219.507 267.690
chr1    11700   11800   190.084 231.024 198.144 229.733
chr1    11800   11900   162.047 218.705 221.881 183.156
chr1    11900   12000   180.203 228.156 241.745 147.520

I would like to know how to restrict values to three decimal places while keeping the header intact.

Khám phá các thẻ bài đăng