Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SED command getting unterminated substitute pattern

I have been using this sed command for 21 months as part of a website backend build command, and it randomly started not working after I updated my computer last time (macOS 15.0.1). The purpose of this sed is to remove comments from SQL files if that helps.

This command still works on the sed tester by gnu (https://sed.js.org/)

$ sed -i 's/--.*//g' sr-api/*.sql;
sed: 1: "sr-api/36ee6939dda495a3 ...": unterminated substitute pattern

Here is the file that it fails on:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

INSERT INTO stagingBuilders SET ?;

Which ironically does not contain any comments.

>Solution :

you’re on OSX? It provides a mostly BSD derived command line userspace. In GNU sed, a suffix to -i is optional. But in BSD sed, a suffix is mandatory with -i. Use -i ''; an empty suffix will change the file in place without a backup, like you expect.

$ sed -i '' 's/--.*//g' sr-api/*.sql;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading