0

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

closed as off-topic by Jeff Schaller, sebasth, Stephen Rauch, xhienne, G-Man Sep 19 '17 at 0:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – Jeff Schaller, sebasth, Stephen Rauch, xhienne, G-Man

1

I would use awk for this rather than a sed substitution:

$ awk -F '[(,]' '{ print $2 }' file
p->name
p->balance
p->number
p->address

It sees each line as a number of fields separated by either ( or ,, and prints the second field.

1
sed 's/[^(]*(\([^,]*\),.*/\1/' input.txt

Input

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

Output

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.