标题: [文本处理] 【已解决】批处理实现特殊字符添加 [打印本页]
作者: a80937063 时间: 2022-5-3 16:36 标题: 【已解决】批处理实现特殊字符添加
本帖最后由 a80937063 于 2022-5-14 18:29 编辑
7.`, 0.27`, 0.36`, 20.7`, 0.045`, 45.`, 170.`, 1.001`, 3.`, 0.45`, 8.8` 6.`,
6.3`, 0.3`, 0.34`, 1.6`, 0.049`, 14.`, 132.`, 0.994`, 3.3`, 0.49`, 9.5`, 6.`,
8.1`, 0.28`, 0.4`, 6.9`, 0.05`, 30.`, 97.`, 0.9951`, 3.26`, 0.44`, 10.1`,6.`,
变化后的结果
{7.`, 0.27`, 0.36`, 20.7`, 0.045`, 45.`, 170.`, 1.001`, 3.`, 0.45`, 8.8`} -> 6.`,
{6.3`, 0.3`, 0.34`, 1.6`, 0.049`, 14.`, 132.`, 0.994`,3.3`, 0.49`, 9.5`} -> 6.`,
{8.1`, 0.28`, 0.4`, 6.9`, 0.05`, 30.`, 97.`, 0.9951`, 3.26`, 0.44`, 10.1`} -> 6.`,
谢谢大神了
作者: flashercs 时间: 2022-5-3 18:44
- @echo off
- cd /d "%~dp0"
- set file=D2.txt
- powershell -c "sc -literal '%file%' -value ((gc -literal '%file%' -read 0)-replace'^([^{].*)[,,\s]+(\S+)','{$1} -> $2')"
- pause
- exit /b
复制代码
作者: a80937063 时间: 2022-5-3 20:07
回复 2# flashercs
什么代码一点看不懂?
数据更换如下:
8188.76, 8180.16, 8015.7, 8068.93, 8231.28, 8365.37, 8369.01, \
8612.85, 8602.38, 8554.79, 8449., 8441.69, 8761.56, 8787.3, 8658.11, \
8503.35, 8512.29, 8291.3, 8210.29, 8349.95, 8584.37, 8589.53, 8513.3, \
8537.97, 8270.69, 8317.22, 8030.9, 7991.64, 8023.93, 8053.04, \
7908.18, 7900.04, 7686.87, 7412.59, 7237.8, 7189.58, 7255.82, 7060.6, \
6555.55, 6123.94, 6889.45, 7407.57, 7366.42, 7244.48, 7538.55, \
变成:11个数字一组加 -> 8888,谢谢
{ 8188.76, 8180.16, 8015.7, 8068.93, 8231.28, 8365.37, 8369.01, 8612.85, 8602.38, 8554.79, 8449.} -> 8441.69,
{ 8761.56, 8787.3, 8658.11, 8503.35, 8512.29, 8291.3, 8210.29, 8349.95, 8584.37, 8589.53, 8513.3} ->8537.97,
{8270.69, 8317.22, 8030.9, 7991.64, 8023.93, 8053.04, 7908.18, 7900.04, 7686.87, 7412.59, 7237.8} ->7189.58,
{7255.82, 7060.6, 6555.55, 6123.94, 6889.45, 7407.57, 7366.42, 7244.48, 7538。55}
作者: flashercs 时间: 2022-5-3 22:03
- @echo off
- setlocal EnableDelayedExpansion
- cd /d "%~dp0"
- set txt=8188.76, 8180.16, 8015.7, 8068.93, 8231.28, 8365.37, 8369.01, 8612.85, 8602.38, 8554.79, 8449., 8441.69, 8761.56, 8787.3, 8658.11, 8503.35, 8512.29, 8291.3, 8210.29, 8349.95, 8584.37, 8589.53, 8513.3, 8537.97, 8270.69, 8317.22, 8030.9, 7991.64, 8023.93, 8053.04, 7908.18, 7900.04, 7686.87, 7412.59, 7237.8, 7189.58, 7255.82, 7060.6, 6555.55, 6123.94, 6889.45, 7407.57, 7366.42, 7244.48, 7538.55,
- :loop
- set n=0
- set max=11
- set /a up=max-1
- for %%A in (%txt%) do (
- if !n! equ 0 (
- set /p s={%%A,<nul
- ) else if !n! equ %up% (
- set /p s=%%A}<nul
- ) else if !n! equ %max% (
- set /p s= -^> %%A,<nul
- set /a n=-1
- ) else (
- set /p s=%%A,<nul
- )
- set /a n+=1
- )
- echo.
- endlocal
- pause
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |