0

Trying to remove a string across multiple files in a directory with sed. The folder contains a large amount of sql files, all with table names that I need to remove. For instance, one of the files looks like this:

INSERT INTO staging.eav_attribute_set (attribute_set_id, entity_type_id, attribute_set_name, sort_order) VALUES (1, 1, 'Default', 2);
INSERT INTO staging.eav_attribute_set (attribute_set_id, entity_type_id, attribute_set_name, sort_order) VALUES (2, 2, 'Default', 2);
INSERT INTO staging.eav_attribute_set (attribute_set_id, entity_type_id, attribute_set_name, sort_order) VALUES (3, 3, 'Default', 1);
INSERT INTO staging.eav_attribute_set (attribute_set_id, entity_type_id, attribute_set_name, sort_order) VALUES (4, 4, 'Default', 1);

I need to remove staging. from all lines. I've tried the following from the directory where the files are:

sed -i 's/staging.//g' *
sed -i 's/staging\.//g' *
sed -i 's|staging.||g' *

But receive the following:

sed: 1: "eav_attribute_set ...": unterminated substitute pattern
  • 1
    Hmmm... That error message does not correspond in any way to the commands that you've been trying. – Kusalananda Aug 28 '18 at 19:22
  • 1
    your tag states "osx" but your title states "Linux". Their sed implementations are different, which one are you using? – Kevin Kruse Aug 28 '18 at 19:22
  • I'm using macos terminal. I've updated my question/title. Good eyes! – mindfullsilence Aug 28 '18 at 19:54
2

With FreeBSD sed (as found on macOS), you need:

sed -i '' 's/staging\.//g' ./*
0

This going to remove staging. in your file.

cat ${yourfile} | sed 's/staging\.//g' > tmp && mv tmp ${yourfile}
  • 1
    That unescaped . will match any character. – RudiC Aug 28 '18 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.