You are not logged in.

#1 2021-04-12 23:11:30

madrafa
Member
Registered: 2021-02-19
Posts: 14

sed command, how to replace any word between quotes in a line?

so, basically I need to do the following:

I have a file and I search for a specific line with certain characters:

grep "style = " file

that gives me a line that looks like this:

style = "foo"

I don't know what can be inside the quotes, I just need to replace whatever is inside the quotes for a new word.

style = "new_word"

I've been searching through various similar questions in stackoverflow and I feel like the best one I found was this:

sed -e 's/-s "[^"]*"/-s "new_word"/'

I've been playing with that one, making some modifications and piping the result of the first grep command into that sed command, but haven't had any look, can anyone help me ?

Offline

#2 2021-04-13 07:00:32

seth
Member
Registered: 2012-09-03
Posts: 22,305

Re: sed command, how to replace any word between quotes in a line?

piping the result of the first grep command into that sed command

Everytime you do that, a fairy dies sad

sed 's/^style = "[^"]*"/style = "new word"/g'

You're not asking together some silly install script that you intend to deploy, are you?
Because I'm not so sure that your pattern is overly robust, blanks are typically compressed by the ini syntax and the "style" key can have different meanings depending on the "[group]" etcetc.

Offline

Board footer

Powered by FluxBB