What would a script to replace \ with / in many files look like?
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 ot开发者_开发问答her 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"
.
sed '/^[ ]*#[ ]*include/ s:\\:/:g'
This should be pretty robust as it should catch any legal format of #include
but not anything else.
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
Sed is the way forward so do it on your mac.
sed '/^#include/s/\\/\//g'
精彩评论