Issue
I have a big config.js file and I would like to replace default:false,
to default:true,
which is on top of field:'$scope.keepEffort'
. I tried multiple sed
command solutions but nothing seems to work.
{
default:false,
enabled:true,
field:'criticalPath',
filter:false,
filterValue:'',
id:'show-critical-path',
operator:'colorize'
},{
default:false,
enabled:true,
field:'$scope.keepEffort',
filter:false,
filterValue:'',
id:'effort-constant',
operator:'var'
},{
default:false,
enabled:true,
field:'$scope.automaticProgress',
filter:false,
filterValue:'',
id:'automatic-progress',
operator:'var'
},{
default:false,
enabled:true,
field:'groupView',
filter:false,
filterValue:'',
id:'gantt-group-view',
operator:'var'
},{
Solution
This is a job for awk
. The following does not attempt to match the single quotes since doing so requires some shell quoting that obfuscates the solution. Also, a trailing {
is printed. That is easy enough to remove, and the code for doing so is omitted for clarity:
awk '/field:.\$scope.keepEffort/{gsub("default:false","default:true")}1' RS=\{ ORS=\{ input-file
The idea is simply to separate the records by {
and then perform the substitution (via gsub
) only on records that match the desired line.
Answered By - William Pursell Answer Checked By - Mildred Charles (WPSolving Admin)