Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed replace forward slash with backslash

I have to convert filenames having a forward slash to filenames with a back slash in a makefile using mingw32. I used the following sed command to store the result in a variable:

ORIGINAL=./a/b/main1.c ./a/b/main2.c ./a/b/main3.c

sed command:

RESULT=$(shell echo $(ORIGINAL) | sed 's/\//\\/g')

And the resulting output is:

.\a\b\main1.c .abmain2.c .abmain3.c

It works fine if I run it directly on bash. Can anyone tell me whats wrong?

Thanks!

like image 484
user2437770 Avatar asked Nov 20 '25 18:11

user2437770


1 Answers

I'm trying to duplicate your test in a makefile, but I don't have your environment. But I would not use '/' as a command separator if I am searching for the same character. Use another character, like ':'

sed 's:/:\\:g'
like image 90
Bruce Barnett Avatar answered Nov 22 '25 13:11

Bruce Barnett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!