1

I'm checking to see if I can replace an include like this:

#include <pathFoo/whatever.H>

with:

#include "whatever.H"

to do so I would use the -i switch, but to check I am doing it correctly I am simply using the -p switch without -i. I have the following command:

perl -p -e 's/<pathFoo\/\(.*\)>/"$1"' thefile

but this isn't quite working and i'm not exactly sure which part is off?

4 Answers 4

4

You don't want to escape the parens, i.e.:

perl -p -e 's/<pathFoo\/(.*)>/"$1"/' thefile

should work for you.

Also note the ending /.

Sign up to request clarification or add additional context in comments.

Comments

1
perl -i~ -pe's!<pathFoo/(.*)>!"$1"!' file

The following is safer:

perl -i~ -pe's!#include\s+\K<pathFoo/(.*)>!"$1"!' file

Comments

1

Since TIMTOWTDI, here's a double substitution. Or rather a substitution and a transliteration:

perl -pe 's|^#include\s+<\KpathFoo/|| && tr/<>/""/'

So, just remove the pathFoo/ part first, and if that succeeds, then transliterate the <> characters to quotes.

Comments

0

I think this will get you there:

perl -pi -e 's{#include[ ]+<.+?/([^/]+)>}{#include "$1"}g' file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.