バッチを使用して txt ファイル内の複数のスペースを 1 つのスペースに置き換える

バッチを使用して txt ファイル内の複数のスペースを 1 つのスペースに置き換える

これが私が得たものです

    @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

ファイルの例は次のとおりです

    P1 something             232
2      232  233
10     232  232
2312   232  232
231    232 323

最初の行を削除する必要がなくなりました。最初の行をスキップせずにスペースを置き換える方法を教えてもらえますか。

答え1

11 行目で、次の行を置き換えます。

FOR /f "skip=1delims=" %%i IN (Text.txt) DO (

FOR /f "delims=" %%i IN (Text.txt) DO (

スペースを含むファイル名に引用符を使用できるようにするには、このStackOverflowの回答によると、以下のオプションを使用できますusebackq:

FOR /f "usebackq delims=" %%i IN ("text 2.txt") DO (

関連情報