开发者

awk / sed script to remove text

I开发者_如何学编程 am currently in need of a way to programmatically remove some text from Makefiles that I am dealing with. Now the problem is that (for whatever reason) the makefiles are being generated with link commands of -l<full_path_to_library>/<library_name> when they should be generated with -l<library_name>. So what I need is a script to find all occurrences of -l/ and then remove up to and including the next /.

Example of what I'm dealing with

-l/home/user/path/to/boost/lib/boost_filesystem

I need it to be

-lboost_filesystem

As could be imagined this is a stop gap measure until I fix the real problem (on the generation side) but in the meantime it would be a great help to me if this could work and I am not too good with my awk and sed.

Thanks for any help.


sed -i 's|-l[^ ]*/\([^/ ]*\)|-l\1|g' Makefile


Here you go

echo "-l/home/user/path/to/boost/lib/boost_filesystem" | awk -F"/" '{ print $1  $NF  } '
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜