Chinaunix首页 | 论坛 | 博客
  • 博客访问: 564614
  • 博文数量: 112
  • 博客积分: 5090
  • 博客等级: 大校
  • 技术积分: 1158
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-19 22:21
文章分类

全部博文(112)

文章存档

2016年(1)

2015年(1)

2012年(1)

2011年(5)

2010年(7)

2009年(6)

2008年(18)

2007年(28)

2006年(16)

2005年(29)

我的朋友

分类:

2009-12-25 17:41:15

a.txt,每三行一个记录:
 

eth0
ge1
00:00.1
eth1
ge2
00:00.2
eth2
ge3
00:00.3


b.awk:

BEGIN {
    FS="\n"
    RS=""
    ORS=""
}
{
    i=1
    while(i<NF){
        print $i "\t"
        if(i%3 == 0)
            print "\n"
        i++
    }
    print $NF "\n"
}

FS          The input field separator, a space by default.

RS          The input record separator, by default a newline.
NF          The number of fields in the current input record.
NR          The total number of input records seen so far.
OFMT        The output format for numbers, "%.6g", by default.
OFS         The output field separator, a space by default.
ORS         The output record separator, by default a newline.


运行 $awk -f b.awk a.txt

eth0 ge1 00:00.1
eth1 ge2 00:00.2
eth2 ge3 00:00.3


阅读(1532) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~