大家好,我需要一点帮助
我正在尝试编辑一个 txt 文件,但它前面没有数据,所以我很难
这是我的剧本
@ECHO Off
setlocal ENABLEDELAYEDEXPANSION
cd /d "%~dp0"
set "Mfind= %Random%"
@For %%G In ("%~dp03Ready\NSB") Do Set "sourcedir=%%~fG"
@For %%G In ("%~dp03Ready\NSBEdited") Do Set "destdir=%%~fG"
Set /p "FPats=Enter Your Amount:
FOR /f "dedestination directory
SET "newdest=%%~dpq"
SET "newdest=!newdest:%sourcedir%=%destdir%!"
SET "newdest=!newdest:~0,-1!"
MD "!newdest!" 2>nul
(
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" "%%q"') do (
set "line=%%b"
if defined line IF "%%b" neq
)
)>"!newdest!\%%~nxq"
)
GOTO :NSBEditing
:nidC1
SET "line=%line:-=%"
SET "original=line%" goto nidC1
set "line=!line:%Mfind%=%Mfind%%FPats%!"
GOTO :eof
这是我的 txt 文件 文本文件 cna reall 的一部分
以下函数可用于修改仅包含空白数字和','的行 表示强制论证,论证位置是固定的。
它使用标志将行标记为仅数字 - 如果删除这些 delims 后该行不为空,则带有 delims 的 For /f 循环会覆盖该标志。
@Echo off
:ReplaceNum <inputfilepath.ext> <outputfilepath.ext>
Set "ScriptName=%~0"
For /f "tokens=1,2* Delims=:" %%G in (":.%ScriptName%")Do If "%%G"=="." Set "ScriptName=Call :%%H"
If "%~1"=="" (
Echo(%ScriptName% ^<inputfilepath.ext^> ^<outputfilepath.ext^>
Exit /B 0
)
%= Error 1; No Source =% If not Exist "%~1" Exit /B 1
%= Error 2; Filepaths Same =% If "%~1"=="%~2" Exit /B 2
Set "Class="
1>"%~2" (
For /f "usebackq delims=" %%G in ("%~1")Do (
Set "Line=%%G"
Setlocal EnableDelayedExpansion
Set "isnum=true"
For /f "delims=0123456789, " %%i in ("!Line!")Do Set "isnum=false"
If "!isnum!"=="true" (
Set "nLine=!Line: =!"
Set "nLine=!nLine:,=!"
Mode 120,40
1> Con Call :GetNum Replace number:'!nLine!' for Class: !Class!
For /f "tokens=1,2" %%i in ("!nLine! !Num!")Do Echo(!Line:%%i=%%j!
Set "Class="
)Else (
Set ^"cLine=!Line:"=!"
For /f "tokens=1,2 delims=:," %%u in ("!Line!")Do If not "%%~b"=="" Set "Class=!Class! %%u"
For %%c in ("{" "}" "[" "]") Do Set "Class=!Class:%%~c=!"
For /L %%i in (1 1 4)Do Set "Class=!Class: = !"
Echo(!Line!
)
For /F "Delims=" %%c in ("!Class!")Do Endlocal & Set "Class=%%c"
)
)
Exit /B 0
:GetNum
( Set LF=^
%= Linefeed Definition - Do not modify =%)
Set "Num="
Set /P "Num=%*!LF!>:"
2> nul Set /A "Num+=0","1/Num" || Goto:GetNum
Exit /B 0
好的。我们来了(再次)...
第一步:(尝试)识别要编辑的行:
@echo off
setlocal EnableDelayedExpansion
set "last=1"
set "lines=:"
for /F "delims=:" %%a in ('findstr /N "{ } ]" (09)Fus.txt') do (
set /A "prev=%%a-2, line=%%a-1"
if !prev! equ !last! set "lines=!lines!!line!:"
set "last=%%a"
)
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" (09)Fus.txt') do (
if "!lines::%%a:=!" neq "%lines%" (
echo %%b ^< - This line will be edited
) else (
echo %%b
)
)
输出示例:
"cpup": [
{
"upma": "id",
"upnn": 0,
"upfb": true,
"upcu": {
"adid": "Dge_ChngerSTemon_2018_nit2",
"ulid": "TT_UPADE_NROU03",
"upty": "NOUS",
"isnc": false,
"erpm": 0
}
},
58, < - This line will be edited
{
"upma": "id",
"upnn": 0,
"upfb": true,
"upcu": {
"adid": "lphaSixoSSCrewcycled_016_tur1",
"ulid": "TT_RADE_TUO02",
"upty": "BO",
"uplv": 1,
"erpm": 0,
"adtc": [
{
"kfti": 1000.0,
"kfva": 0.321
}
]
}
},
70 < - This line will be edited
],
好的。我们来了(再次)...
第一步:(尝试)识别要编辑的行:
@echo off
setlocal EnableDelayedExpansion
set "last=1"
set "lines=:"
for /F "delims=:" %%a in ('findstr /N "{ } ]" (09)Fus.txt') do (
set /A "prev=%%a-2, line=%%a-1"
if !prev! equ !last! set "lines=!lines!!line!:"
set "last=%%a"
)
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" (09)Fus.txt') do (
if "!lines::%%a:=!" neq "%lines%" (
echo %%b ^< - This line will be edited
) else (
echo %%b
)
)
输出示例:
"cpup": [
{
"upma": "id",
"upnn": 0,
"upfb": true,
"upcu": {
"adid": "Dge_ChngerSTemon_2018_nit2",
"ulid": "TT_UPADE_NROU03",
"upty": "NOUS",
"isnc": false,
"erpm": 0
}
},
58, < - This line will be edited
{
"upma": "id",
"upnn": 0,
"upfb": true,
"upcu": {
"adid": "lphaSixoSSCrewcycled_016_tur1",
"ulid": "TT_RADE_TUO02",
"upty": "BO",
"uplv": 1,
"erpm": 0,
"adtc": [
{
"kfti": 1000.0,
"kfva": 0.321
}
]
}
},
70 < - This line will be edited
],