3

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
3
  • 1
    Hmmm... That error message does not correspond in any way to the commands that you've been trying.
    – Kusalananda
    Commented Aug 28, 2018 at 19:22
  • 1
    your tag states "osx" but your title states "Linux". Their sed implementations are different, which one are you using? Commented Aug 28, 2018 at 19:22
  • I'm using macos terminal. I've updated my question/title. Good eyes! Commented Aug 28, 2018 at 19:54

2 Answers 2

8

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
  • 1
    That unescaped . will match any character.
    – RudiC
    Commented Aug 28, 2018 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .