2017-09-18 50 views
0

我必须使用sed提取以下函数调用的第一个参数。在使用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)); 

期待字符串的结果如下。

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

下面的命令打印额外的详细信息,我期待只有第一个参数。

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)); 
+0

如果你是开放给使用其他工具:'grep的-OP '\ bstrlcpy \(\ K [^,] +'' –

+0

这个问题已经交叉张贴在[UNIX和Linux] (https://unix.stackexchange.com/questions/393037/printing-string-between-pattern-using-sed) – John1024

回答

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