regexsed

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:

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/--.*//' sr-api/*.sql;