1

The line

(FOR %F IN ("Q:\Playlists\A 1*.m3u") DO @echo "%~nF")| sed -E "s/.*/x&y/"

produces

x"A 1 T Soft FC La melodia de nuestro adios" y

rather than

x"A 1 T Soft FC La melodia de nuestro adios"y

as expected.

How do I prevent ")" adding this space?

foxidrive
  • 40,353
  • 10
  • 53
  • 68
ChrisJJ
  • 2,191
  • 1
  • 25
  • 38

2 Answers2

1

The problem is the way the command you type is being parsed and executed. Each side of the pipe is executed inside a separate instance of cmd.exe. Those instances do not execute the code you have typed as you have typed it, but a slightly different version that has been reinterpreted by the parser. In this step the aditional space has been included (here you can found a deeper analysis by dbenham)

We can not avoid the way the parser do its work, but we can generate a command where the added spaces do not affect the output

cmd /q /c "(for %f in ("Q:\Playlists\A 1*.m3u") do echo("%~nf")"| sed -E "s/.*/x&y/"
Community
  • 1
  • 1
MC ND
  • 69,615
  • 8
  • 84
  • 126
  • Oh dear. I had not realised how borked CMD truly is. Thanks. FTR, the minimal-change fix based on yours is: cmd /q /c "(FOR %F IN ("Q:\Playlists\A 1*.m3u") DO @echo "%~nF")"| sed -E "s/.*/x&y/" – ChrisJJ Oct 18 '14 at 10:22
  • @ChrisJJ, the `/q` switch in the call to `cmd` means to start with echo off, so, you don't need the `@` prefix. – MC ND Oct 18 '14 at 10:47
  • Thanks. So the minimal-change fix becomes: cmd /c "(FOR %F IN ("Q:\Playlists\A 1*.m3u") DO @echo "%~nF")"| sed -E "s/.*/x&y/" . Does your /q have an advantage over @ ? – ChrisJJ Oct 21 '14 at 14:33
  • @ChrisJJ, in this case, no advantage, there is only one command that needs to be not echoed. I was just pointing to the redundance in the final command. – MC ND Oct 21 '14 at 15:02
0
(@FOR %F IN ("u:\sourcedir\A 1*.m3u") DO @ECHO x"%~nF"y)

worked perfectly well for me. No idea why you're using sed...(I changed the directory to suit my system)

Magoo
  • 77,302
  • 8
  • 62
  • 84