sed/awk replacing cannot work fine in Makefile on Windows

76 Views Asked by At

sed/awk is not working as expected in my Windows Makefile.

I have a text file with \', I want to replace it with ''

cat << EOF > a.txt
\'
\'
''
""
EOF

I can use sed/awk to replace it, this works fine on Windows Git Bash:

sed -i "s/\\\'/''/g" a.txt && cat a.txt

awk '{gsub(/'"\\\'"'/,"\047\047"); print}' a.txt > b.txt && cat b.txt

but with this statement in a Makefile, it will not work:

cat Makefile
replace:
    @sed -i "s/\\\'/''/g" a.txt

re:
    @awk '{gsub(/'"\\\'"'/,"\047\047"); print}' a.txt > b.txt


# run make command, it did nothing but appending '' to each line
make replace && cat a.txt
# or
make re && cat b.txt

\'''
\'''
''''
""''
0

There are 0 best solutions below