我有这个文件:
文件1:
ATOM 1 N LEU 1 -10.186 -21.276 -0.497 1.00 0.00 PROT
ATOM 2 HT1 LEU 1 -10.773 -22.005 -0.843 1.00 0.00 PROT
ATOM 3 HT2 LEU 1 -9.316 -21.441 -0.958 1.00 0.00 PROT
ATOM 4 HT3 LEU 1 -10.007 -21.389 0.478 1.00 0.00 PROT
ATOM 5 CA LEU 1 -10.642 -19.924 -0.729 1.00 0.00 PROT
ATOM 6 HA LEU 1 -10.092 -19.286 -0.214 1.00 1.00 PROT
ATOM 7 CB LEU 1 -10.604 -19.551 -2.214 1.00 1.00 PROT
ATOM 8 HB1 LEU 1 -11.432 -19.802 -2.731 1.00 1.00 PROT
ATOM 9 HB2 LEU 1 -9.764 -19.989 -2.566 1.00 1.00 PROT
ATOM 10 CG LEU 1 -10.447 -17.969 -2.340 1.00 1.00 PROT
当我做:
cat file1 | awk '{printf "%4s%7.0f%5s%5s%5s%12.3f%8.3f%8.3f%6.2f%6.2f%10s\n", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11}'
我得到:
ATOM 1 N LEU 1 -10,000 -21,000 -0,000 1,00 0,00 PROT
ATOM 2 HT1 LEU 1 -10,000 -22,000 -0,000 1,00 0,00 PROT
ATOM 3 HT2 LEU 1 -9,000 -21,000 -0,000 1,00 0,00 PROT
ATOM 4 HT3 LEU 1 -10,000 -21,000 0,000 1,00 0,00 PROT
ATOM 5 CA LEU 1 -10,000 -19,000 -0,000 1,00 0,00 PROT
ATOM 6 HA LEU 1 -10,000 -19,000 -0,000 1,00 1,00 PROT
ATOM 7 CB LEU 1 -10,000 -19,000 -2,000 1,00 1,00 PROT
ATOM 8 HB1 LEU 1 -11,000 -19,000 -2,000 1,00 1,00 PROT
ATOM 9 HB2 LEU 1 -9,000 -19,000 -2,000 1,00 1,00 PROT
ATOM 10 CG LEU 1 -10,000 -17,000 -2,000 1,00 1,00 PROT
输入和输出之间的第 6-8 列不一样。
答案1
如果发生这种情况
- 您的语言环境是
,
小数点分隔符;和 - awk 正在实现数字转换的 POSIX 标准
例如使用 GNU awk (又名gawk
)
$ printf '1.23' | POSIXLY_CORRECT=1 LC_NUMERIC=es_CO.utf-8 gawk '{printf("%.3f\n", $1)}'
1,000
而两者
$ printf '1.23' | LC_NUMERIC=es_CO.utf-8 gawk '{printf("%.3f\n", $1)}'
1.230
$ printf '1.23' | POSIXLY_CORRECT=1 gawk '{printf("%.3f\n", $1)}'
1.230
保留小数。