Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Maybe it is a typo, but the variable is OFMT. According to the AWK manual:
Quote:
According to the POSIX standard, awk’s behavior is undefined if OFMT contains anything but a floating-point conversion specification.
It is a good practice to define OFMT as "%.0f" to print numbers as integers. If the number has some decimal digits, it results in a rounding effect. I hope this will help.
Two notes: 1. the variable OFMT controls the output of the print statement, which internally uses the C function sprintf to convert numbers to strings. If you use the printf statement, you can specify the format as in
Code:
printf "%.0f",$1 # or simply
printf "%d",$1
2. The format specified by the OFMT variable affects only the printing of numbers. But if you try to print an input field as in
Code:
print $1
the output is not affected by OFMT even if $1 represents a numeric value, since variables and fields are considered strings in awk, unless the context forces them to be treated as numbers. A workaround to force awk to consider variables and fields as numbers is to add 0, for example the statement
Code:
print $1+0
force awk to consider $1 as a number, due to the presence of an arithmetic operator and in this case it is affected by the format specified by OFMT.
i might not have been clear but i'm not trying to convert float values or fields within the file to decimal. i'm trying to convert the actual line number output of the incriminated line reported by default by awk as a float if it exceeds 6 digits.
hence i'm actually not sure if OMFT can actually help as coculix outlined...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.