Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on Substituting text in a sed like manner but with a richer format

Post

Substituting text in a sed like manner but with a richer format

+1
−4

I have the following problems working with sed:

  • It doesn't allow multiline operations (thus, no indentations, no nesting)
  • It is generally obligatory to wrap entire commands in quote marks (sed "SED_COMMAND" FILE) even if the command itself contains quote marks.

Without these problems I could format a long liner such as sed -i "s/\$to = ".*";$/\$to = example@example.com;/g" PATH as in this pseudocode:

sed -i
    A
        \$to = ".*";$
    B
        \$to = example@example.com;
    G
PATH
  • A means "from"
  • B means "to"
  • G means "global"

Since sed doesn't work this way, how could I achieve a similar syntax in the shell? Perhaps by using Python? Perl? Something else?

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Point 2 is moot: You can put the Sed script in a file and then the shell doesn't get in your way, all... (4 comments)
Point 2 is moot: You can put the Sed script in a file and then the shell doesn't get in your way, all...
Quasímodo‭ wrote over 2 years ago

Point 2 is moot: You can put the Sed script in a file and then the shell doesn't get in your way, all quotes are literal. Can you clarify point 1? Sed does allow multi-line scripts and can even do multi-line operations.

Canina‭ wrote over 2 years ago

More generally, point 2 is about the shell, not about sed, so any other tool that takes a similar expression as a command line argument would require similar quoting (or other handling) of that expression. It seems to me that this question simply seeks a way to split a sed expression onto multiple lines.

deleted user wrote over 2 years ago

Quasímodo‭ I meant to a full multiline sed command but also with nesting, pretty much like in the pseudocode.

Canina‭ wrote over 2 years ago

deleted user I see no evidence of nesting in the pseudocode in this question. Indentation, yes, but not nesting.