Sed command not working as expected
Having just run across something similar in PowerShell's -replace
just this week, I'm going to theorize that there may be extra characters in your input that you can't see. Try a hexdump -C
on the text you are replacing.
For instance, the wsl.exe
command itself outputs UTF-16 (perhaps even somewhat malformed), which basically puts a 0-byte character after each ASCII character (apologies if my character-encoding terminology isn't quite right):
wsl.exe -l | hexdump -c
:
00000000 57 00 69 00 6e 00 64 00 6f 00 77 00 73 00 20 00 |W.i.n.d.o.w.s. .|
00000010 53 00 75 00 62 00 73 00 79 00 73 00 74 00 65 00 |S.u.b.s.y.s.t.e.|
00000020 6d 00 20 00 66 00 6f 00 72 00 20 00 4c 00 69 00 |m. .f.o.r. .L.i.|
...
A wsl.exe -l | sed 's/W/B/'
will result in:
Bindows Subsystem for Linux Distributions:
Ubuntu (Default)
...
But wsl -l | sed 's/Windows/GatesOS/'
will fail to replace anything, similar to what you are experiencing:
Windows Subsystem for Linux Distributions:
Ubuntu (Default)
...
If this is the problem you are facing, at least the solution under Linux/WSL is easier than it was under PowerShell. Just use iconv
to convert the input from UTF16 to something more manageable, like UTF8:
wsl.exe -l | iconv -f UTF16 -t UTF8 | sed 's/Windows/GatesOS/'
:
GatesOS Subsystem for Linux Distributions:
Ubuntu (Default)
...