ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I want to just take the square for the number of the 6th column and keep the other columns unchanged. And, I really want to keep the format of the input and edited files are exactly same, which means the spaces between columns and the commas and the format of everything all the same after editing.
First, if you omit the FS specification, the sixth fields in the first and second line are 1.185E+00 and 1.495E+00 respectively, because the sixth value is negative and there is no space between the comma and the minus sign. Said that, I think the problem is in the OFMT specification: according to the GAWK manual:
According to the POSIX standard, awk's behavior is undefined if OFMT contains anything but a floating-point conversion specification.
You can override the problem using sprintf to convert $6 in the format you want: