sed字符串搜索和添加参数

sed字符串搜索和添加参数,sed,Sed,我有一个C程序,它在100秒内调用strlcpy函数 strlcpy(p->name,getInfo(NULL,&account)); strlcpy(p->balance,getInfo(NULL,&account)); strlcpy(p->number,getInfo(NULL,&account)); strlcpy(p->address,getInfo(NULL,&account)); 我想使用sed将sizeof([Firs

我有一个C程序,它在100秒内调用strlcpy函数

strlcpy(p->name,getInfo(NULL,&account)); 
strlcpy(p->balance,getInfo(NULL,&account));
strlcpy(p->number,getInfo(NULL,&account)); 
strlcpy(p->address,getInfo(NULL,&account));
我想使用
sed
sizeof([First Parameter])
作为第三个参数添加到strlcpy函数调用中。只能编辑带有strlcpy的行

期望结果是

strlcpy(p->name,getInfo(NULL,&account),sizeof(p->name)); 
strlcpy(p->balance,getInfo(NULL,&account),sizeof(p->balance));
strlcpy(p->number,getInfo(NULL,&account),sizeof(p->number)); 
strlcpy(p->address,getInfo(NULL,&account),sizeof(p->address))

感谢您的任何想法/代码。

sed解决方案:

sed -E 's/^([^(]+)(\([^,]+),([^)]+\)).*/\1\2,\3,sizeof\2));/' file
输出:

strlcpy(p->name,getInfo(NULL,&account),sizeof(p->name));
strlcpy(p->balance,getInfo(NULL,&account),sizeof(p->balance));
strlcpy(p->number,getInfo(NULL,&account),sizeof(p->number));
strlcpy(p->address,getInfo(NULL,&account),sizeof(p->address));

BRE当量:

sed 's/^\([^(]*\)\(([^,]*\),\([^)]*)\).*/\1\2,\3,sizeof\2));/' file

思考:阅读的答案,从中学习,并对这个问题应用相同的技巧。$sed-E的/^([^(]+)([^,]+,([^)]+)./\1\2,3,sizeof\2));/'kk.c sed:非法选项--E$sed的/^([^(]+)(([^,]+),([^)]+)./\1\2,3,sizeof\2));/'kk.csed:命令乱码:s/^([^(+])([^,]+,([^)]+)./\1\2,3,sizeof\2)/@米尼尔,你的操作系统是什么?试用试用试用版SunOS 5.11 sun4v中的
-r
选项version@minil,使用我的BRE方法它不编辑具有空格/空格/制表符的行。你能添加命令吗?