我需要添加文本,無論何時我在此處看到具有部分匹配的「結構」定義。每個結構可以有其他結構,因爲它只是爲了向外部/主結構行添加'typedef'。在行尾將文本添加到bash中的匹配模式中
sed '/;[[:blank:]]*$/!s/^[[:blank:]]*struct/typedef &/' file
typedef struct struct-A {
...
struct struct-B;
};
這sed
命令檢查的;
存在,只有當它不存在它增加了typedef
:
struct struct-A {
...
struct struct-B;
};
到
typedef struct struct-A {
...
struct struct-B;
};
'struct'成員是否像'struct-B'沒有縮進? – eddiem
字段縮進是可選的。 – marc
對於外部結構定義,「{」總是與'struct'在同一行上? – eddiem