[已解决]求助:awk 打印问题
Tofloor
poster avatar
jhkwei
deepin
2011-08-11 00:19
Author
我有原文件 "dr" 格式如下:
NETWORK_NAME_DR
SERVICE_LIST_DR
STUFFING_DR
SATELLITE_DELIVERY_SYSTEM_DR
CABLE_DELIVERY_SYSTEM_DR
VBI_DATA_DR
VBI_TELETEXT_DR
BOUQUET_NAME_DR
SERVICE_DR
COUNTRY_AVAILABILITY_DR
LINKAGE_DR

我想要的格式
#define NETWORK_NAME_DR 0x40
#define SERVICE_LIST_DR      0x41
...

我使用的 awk 语句
awk 'BEGIN {d = 0x3F} c=$1,d++ ; {printf "#define %s  0x%x    ",c,d}' dr

打印却变成了,

NETWORK_NAME_DR
#define NETWORK_NAME_DR  0x40SERVICE_LIST_DR
#define SERVICE_LIST_DR  0x41STUFFING_DR
#define STUFFING_DR  0x42SATELLITE_DELIVERY_SYSTEM_DR
#define SATELLITE_DELIVERY_SYSTEM_DR  0x43CABLE_DELIVERY_SYSTEM_DR
#define CABLE_DELIVERY_SYSTEM_DR  0x44VBI_DATA_DR
#define VBI_DATA_DR  0x45VBI_TELETEXT_DR
#define VBI_TELETEXT_DR  0x46BOUQUET_NAME_DR
#define BOUQUET_NAME_DR  0x47SERVICE_DR
#define SERVICE_DR  0x48COUNTRY_AVAILABILITY_DR

应该怎么写这个 awk ,谢谢!
Reply Favorite View the author
All Replies
stephen
deepin
2011-08-11 00:24
#1
awk 'BEGIN{n=0x40}{printf "#define %s 0x%x\n", $1, n; n++}'
Reply View the author
jhkwei
deepin
2011-08-11 00:35
#2
awk 'BEGIN{n=0x40}{printf "#define %s 0x%x\n", $1, n; n++}'

这样啊,中间不能放语句的啊,谢谢,
Reply View the author