It worked thank you for your valuable time and suggestion.
• 0 views
•
link
I have a file with columns in numbers as data which are in multiple decimal points. i want to change those multiple decimal point data into 2 decimal points.
E.g.
k__Bacteria|p__Proteobacteria 2|1224 18.7582950961843 20.1583624755941
k__Bacteria|p__Actinobacteria 2|201174 13.113604074899 13.9444369113068
to
k__Bacteria|p__Proteobacteria 2|1224 18.75 20.15
k__Bacteria|p__Actinobacteria 2|201174 13.11 13.94
Assuming your data is saved in file.txt:
awk '{printf "%s %s %.2f %.2f\n", $1, $2, $3, $4}' file.txt
This assumes that strings are present in columns 1-2 and prints them unchanged, and reduces numbers in columns 3-4 to two decimals.
If you want the resulting columns to be tab-separated:
awk '{printf "%s\t%s\t%.2f\t%.2f\n", $1, $2, $3, $4}' file.txt
It worked thank you for your valuable time and suggestion.
Log in to answer this question.