First of all, sorry if it is duplicated but I am a totally newbie on Sed. I was assigned to investigate an error log but after fixing it based on some tutorials my problem is still not solved.
Here is the original code:
@sed.exe -i "s/\(.*CONFIG_PROJECT_SW_DATE_VERSION=\"\).*\(\"\)/\1%date:~2,2%%date:~5,2%%date:~8,2%\2/g/" .\ghsproj_du2_avc_src.gpj
after running, I received the following error:
03-27 13:22:43 sed.exe: -e expression #1, char 53: unknown option to `s'
03-27 13:22:43 Could Not Find C:\jenkins-slave\workspace\project\work\build\ghs\sed*
I have read some solutions like remove the blank space between -i and s command or enter a "/" at the end but nothing works so far.
P/S: I ran this on Windows 10 environment.
Try this (GNU sed):
for /f "tokens=2 delims==" %a in ('wmic OS Get localdatetime /value') do set "dt=%a"
sed.exe "s@\(.*CONFIG_PROJECT_SW_DATE_VERSION=\x22\).*\(\x22\)@\1%dt:~2,2%%dt:~4,2%%dt:~6,2%\2@g" file
Change the two %a to %%a if you are putting them in a batch file.
I removed -i switch, add it back when you tested that the output is okay.
Several things to be considered:
sed on cmd or in batch file, thus be careful about the double quotes and the escaping. So I just changed the quotes inside with \x22 which is another way to refer to characters by their ASCII code. (GNU sed feature). cmd or in batch file, %date:~2,2%%date:~5,2%%date:~8,2% does not guaranteed to be YYMMDD, depending on different Locale settings, they can have / inside, maybe it's the cause of your error. I tried another way to get the date, copied the idea from this answer.s command to other character, I changed to @ here. / after the g flag.Example:
> type file
var CONFIG_PROJECT_SW_DATE_VERSION="whatever"
> @for /f "tokens=2 delims==" %a in ('wmic OS Get localdatetime /value') do @set "dt=%a"
> sed.exe "s@\(.*CONFIG_PROJECT_SW_DATE_VERSION=\x22\).*\(\x22\)@\1%dt:~2,2%%dt:~4,2%%dt:~6,2%\2@g" file
var CONFIG_PROJECT_SW_DATE_VERSION="190327"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With