I have a file.
$ cat file
"bar": false
"foo": false
I need to replace the word false
with true
only in the pattern "foo": false
. The problem is quotes and spaces.
I thought about two ways:
- To isolate the whole pattern in some sort of qoutes/double quotes.
- To replace only such "false" which has a "foo" before it.
An example try of 2 option:
$ sed -i 's/\(.*foo\)/false/true\1/g' file
It failed.
Use an address. The quotes are not a problem if you single quote your
sed
expressionIf you really need to match the whole pattern, fine:
*
matches any number of the preceding character (space).You can use
\s
to also match tabs (any horizontal whitespace):Add the
-i
option after testing to modify the original file.