-1

I have a log file, like this:

compile.log

C:\Program Files\File.ext(25,10) : error <ERROR_CODE>: <ERROR_MESSAGE>
C:\Program Files\File.ext(36,13) : error <ERROR_CODE>: <ERROR_MESSAGE>
C:\Program Files\File.ext(41,51) : warning <WARNING>: <WARNING>
C:\Program Files\File.ext(64,55) : error <ERROR_CODE>: <ERROR_MESSAGE>
 : information: result 3 error(s), 1 warning(s)

And want it like this:

compile.log

/Users/user/Library/Folders/Program Files/File.ext(25,10) : error <ERROR_CODE>: <ERROR_MESSAGE>
/Users/user/Library/Folders/Program Files/File.ext(36,13) : error <ERROR_CODE>: <ERROR_MESSAGE>
/Users/user/Library/Folders/Program Files/File.ext(41,51) : warning <WARNING>: <WARNING>
/Users/user/Library/Folders/Program Files/File.ext(64,55) : error <ERROR_CODE>: <ERROR_MESSAGE>
 : information: result 3 error(s), 1 warning(s)

Tried numerous sed and awk alternatives with various error messages.
Could someone show me a working (macOS 10.14.1) solution?


UPDATE: Everything works as expected, after I converted compile.log to UTF-8. Seemingly the windows environment created the log utf-16le encoded.

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172

1 Answers1

1

sed 's/C:\\Program Files\\File.ext/\/Users\/user\/Library\/Folders\/Program Files\/File.ext/g' compile.log > compile-replaced.log

Whosphp
  • 26
  • 3
  • Thanks! However, it actually shows an empty `compile-replaced.log`. It says: `sed: RE error: illegal byte sequence` – Geri Borbás Jun 21 '19 at 01:50
  • use `s\@...@...@` form for search targets that include `/` chars (you may or may not need the leading `\` char. Good luck. – shellter Jun 21 '19 at 01:53
  • Now it is either a `sed: 1: "s\@C:\\Program Files@\/ ...": substitute pattern can not be delimited by newline or backslash` or the `sed: RE error: illegal byte sequence` without the leading \. – Geri Borbás Jun 21 '19 at 01:57
  • 1
    @Geri Maybe you should get more info here [https://stackoverflow.com/questions/19242275/re-error-illegal-byte-sequence-on-mac-os-x] – Whosphp Jun 21 '19 at 01:58
  • Thanks, I did get the info there (been trial and erroring for hours now), but the strings did not get replaced (`compile-replaced.log` have the same content as the original). – Geri Borbás Jun 21 '19 at 02:02
  • Thanks, it was an encoding issue, nothing in particular with `sed`. Nevertheless, the answer works just fine. – Geri Borbás Jun 21 '19 at 02:10
  • When working with directory paths it's better to just choose some other delimiter than `/` for the sed command so you don't need to escape all the `/`s in the path, e.g.: `s:/abc/def:/ghi:` instead of `s/\/abc\/def/\/f\ghi/'` – Ed Morton Jun 21 '19 at 03:48
  • 1
    @Geri : Check your `LANG` variable, whether it matches the encoding for the file. – user1934428 Jun 21 '19 at 05:26