minil
minil

Reputation: 7135

Printing string between pattern using 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));

Upvotes: 0

Views: 59

Answers (1)

Ed Morton
Ed Morton

Reputation: 203502

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

Upvotes: 3

Related Questions