In bat, I wrote something to replace the characters in a file, but line breaks and spaces disappear.
Please tell me how to solve this problem.
@echo off
Copy rem source file to temp
copy%~n1.tex"%~n1"_temp.tex
Remove rem source file
del "% to n1.tex"
setlocal enabled delayed expansion
for /f "delims="%%ain(%~n1_temp.tex)do(
set line = %%a
set line=!line:.=.!
set line=!line: , =, !
echo!line!>>% to n1.tex
)
endlocal
I don't know the details of line breaks and spaces disappear, so I'm not sure if it applies to all the data, but I think it's because of the way echo is written.
Replace strings with .bat batch files in windows
because of echo
·It is assumed that there were no empty lines
·Echo off is output for lines with only half-width spaces
Additionally, the output of substitution for environment variables will apply to the following:
It's good to write some kind of symbol right after echo.Most symbols are fine, but the most common ones are ./: and so on.
However, if echo. is used, it is not allowed to include the letter = between !! and !!.
Now, you can use one of the following symbols after echo: ;=.
On the contrary, the output may be blanked.
Batch files|Read text files line by line (full version?)
6. Bonus: It might be good to enclose echo in parentheses
Based on the above, please try the echo line as follows.
Please try various things such as whether or not it has parentheses and changing the symbols used.
(echo=!line!)>>% to n1.tex
Furthermore, I'm Nan, but FOR/F is the default value of eol= and the line starts with semicolon
The line is treated as a comment line and skipped, which seems difficult to avoid.
Other than that, if you specify setlocal enabled delayed expansion, the target file name will be restricted.
Notes to avoid trial and error in batch files
@sayuri-san I think it would be better to try PowerShell or use commands such as sed or awk(gawk) that specialize in editing and string processing.
GNU utilities for Win32
Additional information.If you use sed for bat, perhaps the easiest way is to introduce git bash.
MinGW will also be included during setup, so you can use it normally from the command prompt.
https://gitforwindows.org/
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
581 PHP ssh2_scp_send fails to send files as intended
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.