AWK使系统较少依赖 [英] awk make it less system dependant

查看:93
本文介绍了AWK使系统较少依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我没有记错,这取决于操作系统的语言(例如,回声1,2AWK分析了一些| awk的'{printf的(%F \\ n,$ 1)} 将在英语系统和1.2在一个逗号的整数小数部分分开的系统)作为PTED 1间$ p $。

If I'm not mistaken, awk parses a number depending on the OS language (eg,echo "1,2" | awk '{printf("%f\n",$1)}' would be interpreted as 1 in an english system and as 1.2 in a system where a comma separates the integer from the decimal part).

我不知道如果C的printf确实这也太,所以我将它们加​​入C标记。

I don't know if the C printf does this too, so I added the C tag.

我想修改previous命令,使其返回相同的值(1.2)无论系统中使用。

I would like to modify the previous command so that it returns the same value (1.2) regardless of the system being used.

推荐答案

欢迎到的的丑恶区域的。要解决你的问题,首先设置区域设置到C之一。

Welcome to the ugliness of locale. To fix your problem, first set the locale to the C one.

export LC_NUMERIC=C
echo "1,2" | awk '...your code...'

要关闭其他区域设置相关的蠢事,你可以

To turn off other locale-dependent tomfoolery, you can

export LC_ALL=C

这篇关于AWK使系统较少依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆