views:

51

answers:

3

Yes, this is a really lazy question but I figure this is problem that people have often enough that someone here would have something already written to share.

I have a ton of C files with #include statements using Windows relative paths. I'm working on compiling the code on other operating systems (immediately, on my OS X development machine) and need to replace all the backslashes with forward slashes in these include statements. So, from something like #include "libs\helper.h" to #include "libs/helper.h".

+2  A: 
sed  '/^[ ]*#[ ]*include/ s:\\:/:g'

This should be pretty robust as it should catch any legal format of #include but not anything else.

R Samuel Klatchko
+1  A: 

you should have bash/awk/sed in OS X

for cfile in *.c
do
  awk '/#include/{gsub(/\\/,"/")}1' cfile >temp
  mv temp cfile
done

or

 sed -i.bak '/#include/s/\\/\//g' *.c
ghostdog74
You could have chosen a different delimiter...
Anon.
A: 

Sed is the way forward so do it on your mac.

sed '/^#include/s/\\/\//g'

Tom Duckering