(Couldn't come with any better title)
I'm trying to convert a number of lines, like these:
#define GENERIC_TYPE_METER_PULSE 0x30 /*Pulse Meter*/
#define SPECIFIC_TYPE_NOT_USED 0x00 /*Specific Device Class not used*/
......
#define MFG_ID_WAYNE_DALTON 0x0008 //Wayne Dalton
#define MFG_ID_WILSHINE_HOLDING_CO_LTD 0x012D //Wilshine Holding Co., Ltd
#define MFG_ID_WIDOM 0x0149 //wiDom
......
#define COMMAND_CLASS_ALARM 0x71
#define COMMAND_CLASS_ALARM_V2 0x71
#define COMMAND_CLASS_NOTIFICATION_V3 0x71
#define COMMAND_CLASS_NOTIFICATION_V4 0x71
in a file (c++) to something like these (for Java):
SPECIFIC_TYPE_NOT_USED((byte)0x00) /*Specific Device Class not used*/
MFG_ID_WILSHINE_HOLDING_CO_LTD((byte)0x012D) //Wilshine Holding Co., Ltd
COMMAND_CLASS_ALARM((byte)0x71)
....
I came up with this:
gawk '/^#define/ && / [[:xdigit:]]/ { printf "%s((byte)%s)\n",$2,$3 }'
but there are two issues - it doesn't work with awk
; requires GNU-awk (gawk
) and I also need the end-of-the-line comments in the output whenever available. How can I do that? I'm especially interested using awk
but can live with sed
as well. Cheers!!