
Aqui está o que eu tenho
@ECHO OFF
SETLOCAL
::
:: delete first line/lines
:: and replace each occurrence of 2 or more spaces
:: by a delimiter
::
DEL outfile.txt 2>nul /F /Q
:: replace with ->
SET delim=
:: set number of lines to delete
FOR /f "skip=1delims=" %%i IN (Text.txt) DO (
SET line=%%i
(SET newline=)
SET count=0
CALL :change
)
GOTO :eof
:CHANGE
SET c1=%line:~0,1%
SET line=%line:~1%
IF "%c1%"==" " (SET /a count+=1) ELSE (
IF %count%==0 (SET newline=%newline%%c1%) ELSE (
IF %count%==1 (SET newline=%newline% %c1%) ELSE (
SET newline=%newline%%delim%%c1%)
SET count=0
)
)
IF DEFINED line GOTO CHANGE
::
:: You may want to preserve trailing spaces
:: or convert them...
::
IF %count%==0 GOTO print
IF %count%==1 SET newline=%newline% &GOTO print
SET newline=%newline%%delim%
:PRINT
>>outfile.txt ECHO %newline%
GOTO :eof
Aqui está um exemplo de arquivo
P1 something 232
2 232 233
10 232 232
2312 232 232
231 232 323
Não preciso mais deletar a primeira linha, alguém pode me ajudar a descobrir como substituir os espaços sem pular a primeira linha/linhas.
Responder1
Na linha 11, substitua:
FOR /f "skip=1delims=" %%i IN (Text.txt) DO (
com
FOR /f "delims=" %%i IN (Text.txt) DO (
Para permitir o uso de aspas para nomes de arquivos com espaços,por esta resposta do StackOverflow, você pode usar a usebackq
opção:
FOR /f "usebackq delims=" %%i IN ("text 2.txt") DO (