views:

84

answers:

2

Hi,

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.

+4  A: 
sed -i 's|-l[^ ]*/\([^/ ]*\)|-l\1|g' Makefile
Ignacio Vazquez-Abrams
I'd add whitespace in front of the `-l` to avoid matching `-lrelative-librarypath/lib`
msw
works like a charm for my purposes, thanks :)
radman
A: 

Here you go

echo "-l/home/user/path/to/boost/lib/boost_filesystem" | awk -F"/" '{ print $1  $NF  } '
Kunal
That handles your single test case, but not the general problem of multiple instances on lines containing other text. awk is happiest on line actions, you could add a pattern to the scriptlette but sed is the better choice here.
msw