0

I have the following code generated in a Makefile:

    ${SED} -i '' -e "s|(DESTDIR)|${DESTDIR}|g" $(pcfiles)
#   ${SED} -i "s|(DESTDIR)|${DESTDIR}|g" $(pcfiles)

Which I want to replace with

#   ${SED} -i '' -e "s|(DESTDIR)|${DESTDIR}|g" $(pcfiles)
    ${SED} -i "s|(DESTDIR)|${DESTDIR}|g" $(pcfiles)

So it's simply a matter of commenting out one line,and replacing with the other.

But due to the single quotes and double quotes I can't achieve it.

If some regex expert is willing to take 1-2 minutes to help me out that will be great.

I'm pulling my hairs out here.

Thanks

2
  • If it's generated in a Makefile consider fixing the source. If it were to be generated again, you'd need to run a script in order to fix it. Commented Feb 13, 2014 at 14:35
  • Badly i can't fix the source because it's generated & cross-compiled on Mac. If you can help with a simple 'sed' change that would be perfect. Commented Feb 13, 2014 at 14:42

1 Answer 1

1
# Comment out 1st line.
sed -E 's`([[:space:]]*\$\{SED\} -i '"''"' -e "s\|\(DESTDIR\)\|\$\{DESTDIR\}\|g" \$\(pcfiles\))`#\1`' Makefile
# Uncomment 2nd line.
sed -E 's`#([[:space:]]+\$\{SED\} -i "s\|\(DESTDIR\)\|\$\{DESTDIR\}\|g" \$\(pcfiles\))`\1`' Makefile 

The sed commands are in single-quoted strings, which are generally easier to use (you needn't worry about the shell expanding your string).

The tricky aspect of the first command is that single quotes cannot be included in a single-quoted string (even escaping is not an option), so the command is simply broken into two single-quoted strings with "''" - amounting to '' - spliced in.

The other tricky aspect is to get the escaping of all special regex chars. right.

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

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.