简体   繁体   中英

how to find/replace string in file

I'm trying to find in file this string:

"cPHulk":{"BruteForce":3,"Login":3,"*":3}

and replace it with this string:

"cPHulk":{"*":"1","Login":"1","BruteForce":"1"}

I'm using sed to do this but I struggle a lot. My sed command is as follow:

sed -i -e 's/"cPHulk":{"BruteForce":3,"Login":3,"*":3}/"cPHulk":{"*":"1","Login":"1","BruteForce":"1"}/g' /var/cpanel/icontact_event_importance.json

EDIT: The correct sed formula:

sed -i -e 's/"cPHulk":{"BruteForce":3,"Login":3,"\*":3}/"cPHulk":{"\*":"1","Login":"1","BruteForce":"1"}/g' /var/cpanel/icontact_event_importance.json

I found on some *nix you must provide a blank as the suffix to get it make an in-place replacement:

sed -i '' -e 's/"cPHulk":{"BruteForce":3,"Login":3,"*":3}/"cPHulk":{"*":"1","Login":"1","BruteForce":"1"}/g' /var/cpanel/icontact_event_importance.json

Note the '' after -i

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM