replacing a path with sed

Posted by compie on Stack Overflow See other posts from Stack Overflow or by compie
Published on 2010-03-07T10:07:34Z Indexed on 2010/03/11 21:24 UTC
Read the original article Hit count: 191

Filed under:
|
|

How can I use sed to replace this line

char * path_list_[1] = { "/some/random/path" };

with this line

char * path_list_[2] = { "lib/foo", "lib/bar" };

in a file named source.c

Notes:
* The path is really random.
* Your solution should only change this line in source.c
* I'm only interested in a sed oneliner.

You can use this Python regex as a starting point:

text = re.sub('static const char \* path_list_\[1\] = \{ "[^"]*" \};', 
    'static const char * path_list_[2] = { "lib/sun", "lib/matlab" };', text)

© Stack Overflow or respective owner

Related posts about sed

Related posts about regex