0

I am having challenges formatting some files. I want to delete everything between the [&lnP until the [&R] in the file1.trees and then create a new file called file1_edit.trees. But I am getting the error 'bad flag in substitute command: '/''

 sed -i '' 's/[&lnP/,/[&R]/{//!d;}/g' file1.trees > file1_edit.trees Error --->> sed: 1: "s/[&lnP/,/[&R]/{//!d;}/g": bad flag in substitute command: '/' 
3
  • 1
    escape square brackets, remove rediection as you are doing inplace updates. Commented Oct 4, 2017 at 11:46
  • Not sure, but maybe you means sed 's/[&lnP\/,/[&R]/{\/!d;}/g' Commented Oct 4, 2017 at 11:49
  • It's not completely clear what you're trying to achieve - could you edit to add a (small) sample input and expected output? As it is, I can't tell whether you're trying to s (substitute) within a line or to d (delete) a range of lines. Commented Oct 4, 2017 at 12:27

1 Answer 1

0

Assuming you want to replace "[&lnP/,/[&R]" with "{//!d;}", your command should be:

sed 's/\[&lnP\/,\/\[&R\]/{\/\/!d;}/g' file1.trees > file1_edit.trees 

You would need to escape characters which would get confused with search/replace part by having forward slash. Also escape characters which would be treated as a special characters in regex (meta characters).

Also remove -i flag which would do the changes inplace into the file.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.