Reputation: 162
I want to replace a string in a file using command, but the thing is the string is such
"https": false,
I want to change it to
"https": true,
and vice versa.
is there any way to accomplish this thru command? Am developing auto script so whenever a user logins this command kicks in, I have sorted everything except this.
Upvotes: 3
Views: 2335
Reputation: 4551
Use sed
:
sed -i 's/"https": false,/"https": true,/g' /path/to/file
Here the -i
flag means replace and save the file using the same name. Any occurrence of "https": false,
will be replaced with "https": true,
/ If this string only occurs at the start of a line, use this instead:
sed -i 's/^"https": false,/"https": true,/' /path/to/file
This substitution is executed on the specified file, where you can also use wildcards to perform it on multiple files, e.g. /path/tp/dir/*
(all files in dir) or *java
(all java files).
Upvotes: 6