English 中文(简体)
你们如何在Awk One-Liners/Single突击队中纳入短功能?
原标题:How do you Include Short Functions in Awk One-Liners/Single Commands?

我知道,你通常不希望一线指挥员/单列指挥员太长,但似乎有时会有一个长途的单行,以职能取代重复性的内容。

是否有可能利用短职能缩短你的指挥时间?

例如,根据我的知识,我没有上限或双轨功能,因此你可以书写职能。

 function round(a){a=(a < int(a)+0.5) ? int(a) : int(a+1)} 

以及

 function ceil(a){a=(a == int(a)) ? a : int(a)+1} 

您能否将这些职能纳入一个线人?

e.g.

您能否用纸件获取文件上限

$ cat money.data
121.52 133.45 136.77 155.22
132.11 141.30 12.78 78.98
31.21 149.03 33.50 84.67

......最高职能是:

$ tail money.data
122 134 137 156
133 142 13 79
32 150 34 85

...以及 for the round function would be

$ tail money.data
122 133 137 155
132 141 13 79
31 149 34 85

I played around with r以及om awk statements, but couldn t figure out how to incorporate the functions into one liners...

最佳回答

在你的职责中仅使用返回声明:

function round(a){return (a < int(a)+0.5) ? int(a) : int(a+1)}
{for (f=1;f<=NF;f++) print round($f)}

职能按价值而不是参照,因此变值的变动不影响电传变量。

问题回答

暂无回答




相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签