【问题标题】:Add additional characters to strings in file using sed使用 sed 向文件中的字符串添加其他字符
【发布时间】:2019-05-02 07:57:58
【问题描述】:

我有.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 命令一次性替换所有这些吗?

【问题讨论】:

  • 我是sed 命令的新手,我没有得到任何关于添加字符串的信息,而是有很多关于替换现有字符串的主题。

标签: linux bash shell sed


【解决方案1】:

假设_c__In_ 之间总是有一些字符串,在_In_ 之后:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 2018-07-17
    • 2020-04-08
    • 1970-01-01
    • 2019-12-07
    • 1970-01-01
    相关资源
    最近更新 更多