Timeline for sed command to replace and write
Current License: CC BY-SA 4.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 16, 2018 at 18:01 | comment | added | user3613331 | #!/bin/bash currentSchema="$( awk '/schema/ {print $3}' rex.json )" awk '/schema/ {sub ($currentSchema, "BBBBB-BBBBB-BBBBB-BBBBB-BBBBB", $3)} 1' rex.json > /tmp/$$ && mv /tmp/$$ yy.json still yy.json is not updating | |
| Oct 16, 2018 at 17:40 | comment | added | RudiC | Try awk '/schema/ {sub ("AAAA", "BBBBB", $3)} 1' test.json, then. | |
| Oct 16, 2018 at 17:38 | comment | added | user3613331 | currently, rex.json contains "schema" : "AAAAA-AAAAA-AAAAA-AAAAA-AAAAA", I tried the following command awk '/schema/ {$3 = "BBBBB"} 1' rex.json > /tmp/$$ && mv /tmp/$$ yy.json Now yy.json has "schema" : BBBBB Almost there... I need to keep double-quotes there itself along with comma. Basically the entire line should be same. | |
| Oct 16, 2018 at 17:35 | comment | added | user3613331 | oops... please excuse.. let me update the contents in rex.json | |
| Oct 16, 2018 at 17:33 | comment | added | user3613331 | awk '/schema/ {$3 = "BBBBB"} 1' rex.json > /tmp/$$ && mv /tmp/$$ yy.json But yy.json contains the same AAAAA itself.. did not change. Where rex.json contains "AAAAA-AAAAA-AAAAA-AAAAA-AAAAA", | |
| Oct 16, 2018 at 17:32 | comment | added | RudiC | @DopeGhoti: Not sure I understand? | |
| Oct 16, 2018 at 17:30 | comment | added | DopeGhoti | That will change the entire .json file to only the newly-changed line, discarding the rest of the contents. | |
| Oct 16, 2018 at 17:28 | history | answered | RudiC | CC BY-SA 4.0 |