awk FIELDWIDTHS如何运作 [英] how does awk FIELDWIDTHS WORK

查看:115
本文介绍了awk FIELDWIDTHS如何运作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我开始学习awk编程(有效的awk脚本).在第102页上,作者正在解释字段宽度,但是我不明白它是如何工作的.请有人可以向我解释一下,fieldwidths是如何工作的?

I started learning awk programming few days back (Effective awk scripting). At page 102 the author was explaining fieldwidths, but I don't understand how it works. Please could someone kindly explain to me, how fieldwidths works?

推荐答案

FIELDWIDTHS 用空格分隔的字段宽度列表.设置好后, gawk将输入解析为固定宽度的字段,而不是使用 FS变量的值作为字段分隔符.

FIELDWIDTHS A whitespace separated list of field widths. When set, gawk parses the input into fields of fixed width, instead of using the value of the FS variable as the field separator.

我认为有一个更好的例子来解释它是如何工作的:

I think an example is better to explain how does it work:

$ echo "aaabbbbcccccdddddd"|awk -v FIELDWIDTHS="3 4 5 6" '{for(i=1;i<=NF;i++)print $i}'    
aaa
bbbb
ccccc
dddddd

当很难找到记录的FS,但是记录具有固定长度字段时,这很有用.

It is useful, when it is difficult to find a FS of the record, but the record has fixed length fields.

这篇关于awk FIELDWIDTHS如何运作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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