2017-09-18 54 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 
相關問題