1

I have a line that looks like this:

"startTime": "2022:12:03T10:00:00Z",

I want to replace the the date with another date 'dtime', assuming file path is all given:

sed -i 's/"startTime":".*/"startTime":"'$dtime'",/' $filePath

but this does not work. I'm using Mac and wondering if there are any specifics related to Mac.

Steve
  • 129
  • 1
  • 14
  • Please take a look at [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Cyrus Apr 07 '23 at 19:44
  • 2
    The Mac version of `sed` requires an argument after the `-i` flag. `sed -i '' ...` – Barmar Apr 07 '23 at 19:45
  • I tried to add '' as sed -I '' ... but I get the error: sed: can't read 's/"startTime":".*/"startTime":"2022:12:03T11:00:00Z",/: No such file or directory – Steve Apr 07 '23 at 19:49
  • Use a lowercase `-i`. – Cyrus Apr 07 '23 at 19:59
  • I did!! it's Mac that's so smart – Steve Apr 07 '23 at 20:00
  • BTW, in general, `sed` is the wrong tool for editing JSON; use `jq` or another proper JSON parser instead. (`jq --arg newStartTime "$dtime" '.startTime = $newStartTime' new.json` is an example of what this might look like). – Charles Duffy Apr 07 '23 at 20:18

0 Answers0