使用sed在模式之间打印字符串 [英] Printing string between pattern using sed

查看:53
本文介绍了使用sed在模式之间打印字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用 sed 提取以下函数调用的第一个参数.

I have to extract the first parameter of the following function calls using sed.

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

期望字符串的结果如下.

Expecting the result of string as below.

p->name
p->balance
p->number
p->address

以下命令打印附加详细信息,我只需要第一个参数.

The following command prints the additional details, I am expecting only the first parameters.

 sed -n 's/strlcpy(\(.*\),/\1/p' kk.txt

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

推荐答案

 sed -n 's/.*strlcpy(\([^,]*\).*/\1/p' kk.txt

这篇关于使用sed在模式之间打印字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆