gpt4 book ai didi

windows - 如何将零填充到文件内容中?

转载 作者:可可西里 更新时间:2023-11-01 11:47:09 30 4
gpt4 key购买 nike

尝试将两位数的 34/0/2 填充为 34/0/02。我的代码。建议....?

@echo off
SETLOCAL enableDelayedExpansion
FOR /F "tokens=1,2,3,4,5* delims=,/" %%a IN (temp1.csv) do (
echo orig %%a/%%b/%%c,%%d,%%e
echo new %%a/%%b/%c:~-2%,%%d,%%e >> temp3.csv
)
type temp3.csv

temp1.csv 文件内容

Gi-34/0/1,lpu,w-3-016ch1swA1p19_lag   
Gi-34/0/10,lpu,w-3-018ch1swA2p19_lag
Gi-34/0/11,lpu,prodca1_lan_sec
Gi-34/0/12,lpu,prodca2_lan_sec
Gi-34/0/13,lpd,
Gi-34/0/14,lpd,
Gi-34/0/15,lpd,
Gi-34/0/16,lpd,
Gi-34/0/17,lpd,
Gi-34/0/18,lpu,aix_to_hmc
Gi-34/0/19,lpu,prodcafl1_lan_sec
Gi-34/0/2,lpu,w-3-016ch1swA2p19_lag
Gi-34/0/20,lpu,prodcafl2_lan_sec

最佳答案

将当前内容加到100取最后两位比较容易。您引用了一个不存在的 var %c%。为了更好地区分,我使用了带有延迟扩展的大写 var !C!。只有 3 个变量,其余的是 tokens=1-3*

@echo off
SETLOCAL enableDelayedExpansion
Type Nul >temp3.csv
FOR /F "tokens=1-3* delims=,/" %%a IN (temp1.csv) do (
echo orig %%a/%%b/%%c,%%d
Set /A C=100 + %%c
echo new %%a/%%b/!C:~-2!,%%d >> temp3.csv
)
type temp3.csv

示例输出:

new Gi-34/0/01,lpu,w-3-016ch1swA1p19_lag
new Gi-34/0/10,lpu,w-3-018ch1swA2p19_lag
new Gi-34/0/11,lpu,prodca1_lan_sec
new Gi-34/0/12,lpu,prodca2_lan_sec
new Gi-34/0/13,lpd,
new Gi-34/0/14,lpd,
new Gi-34/0/15,lpd,
new Gi-34/0/16,lpd,
new Gi-34/0/17,lpd,
new Gi-34/0/18,lpu,aix_to_hmc
new Gi-34/0/19,lpu,prodcafl1_lan_sec
new Gi-34/0/02,lpu,w-3-016ch1swA2p19_lag
new Gi-34/0/20,lpu,prodcafl2_lan_sec

关于windows - 如何将零填充到文件内容中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42212960/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com