使用sed

时间:2019-05-02 07:57:58

标签: linux bash shell sed

我有以下.h文件

//Structure
typedef struct VIN_oFDCAN8_8d836e25_In
{
vbittype unused31 : 8;
vbittype unused30 : 8;
vbittype unused29 : 8;
vbittype unused28 : 8;
vbittype unused27 : 8;
vbittype unused26 : 8;
vbittype unused25 : 8;
vbittype unused24 : 8;
vbittype unused23 : 8;
vbittype unused22 : 8;
vbittype unused21 : 8;
vbittype unused20 : 8;
vbittype unused19 : 8;
vbittype unused18 : 8;
vbittype unused17 : 8;
vbittype VIN_DATA_AH_C : 56;
vbittype unused9_0 : 2;
vbittype VIN_MSG_AH_C : 2;
vbittype unused9_1 : 4;
vbittype unused8 : 8;
vbittype unused7 : 8;
vbittype unused6 : 8;
vbittype unused5 : 8;
vbittype unused4 : 8;
vbittype unused3 : 8;
vbittype unused2 : 8;
vbittype unused1 : 8;
vbittype unused0 : 8;
}__attribute__((packed))_c_VIN_oFDCAN8_8d836e25_In_msgType;


//union
typedef union _c_VIN_oFDCAN8_8d836e25_In_bufTag
{
    vuint8 _c[32];
    _c_VIN_oFDCAN8_8d836e25_In_msgType VIN_oFDCAN8_8d836e25_In;
} _c_VIN_oFDCAN8_8d836e25_In_buf;


//Declaration
_c_VIN_oFDCAN8_8d836e25_In_buf  VIN_oFDCAN8_8d836e25_In_data;

如您所见,所有类型名称都以_c_开头。

_c_VIN_oFDCAN8_8d836e25_In_msgType
_c_VIN_oFDCAN8_8d836e25_In_bufTag
_c_VIN_oFDCAN8_8d836e25_In_buf

我想向他们添加_Moto_标签,如下所示。

_c_VIN_oFDCAN8_8d836e25_In_Moto_msgType
_c_VIN_oFDCAN8_8d836e25_In_Moto_bufTag
_c_VIN_oFDCAN8_8d836e25_In_Moto_buf

我有很多这样的定义,在这样的定义中可以找到的常见标签是_c_

您能用sed命令帮我一次更换所有镜头吗?

1 个答案:

答案 0 :(得分:0)

假设_c__In_之间以及_In_之后始终有一些字符串:

sed 's/_c_[[:alnum:]_]*_In_/&Moto_/g' file.h

应该工作。它匹配_c_<zero or more alphanumeric chars and underscores>_In_,并在其后添加Moto_