Board logo

标题: [文本处理] 批处理将多行内容在每行首尾添加指定字符串后合并成一行,如何删除最后一个指定字符 [打印本页]

作者: websfx    时间: 2016-8-12 17:00     标题: 批处理将多行内容在每行首尾添加指定字符串后合并成一行,如何删除最后一个指定字符

本帖最后由 pcl_test 于 2016-8-12 17:24 编辑

如何让多行内容合并一行,并在每一个后面添加一个 逗号
如题
Hotfix.txt 文本内容如下:
www.aaaa.com
www.aaaa.com
www.bbb.com
www.assfj.com
www.sjfdlsf.com
www.123.com
sadfjsa.tao.com
www.aaaa.com
www.bbb.com

我想要得到的结果是
http/*:80:www.aaaa.com,http/*:80:www.aaaa.com,http/*:80:www.bbb.com,http/*:80:www.assfj.com,http/*:80:www.sjfdlsf.com,http/*:80:www.123.com,http/*:80:sadfjsa.tao.com,http/*:80:www.aaaa.com,http/*:80:www.bbb.com,http/*:80:www.assfj.com,http/*:80:www.sjfdlsf.com,http/*:80:www.123.com,http/*:80:sadfjsa.tao.com,http/*:80:www.bbb.com,http/*:80:www.assfj.com,http/*:80:www.sjfdlsf.com,http/*:80:www.123.com,http/*:80:sadfjsa.tao.com

这是我写的
@echo OFF
setlocal EnableDelayedExpansion
for /f "delims=" %%i in (Hotfix.txt) do call set "var=%%var%%http/*:80:%%i,"
echo %var%
pause

出现结果是我想要的  不过 最后多了一个 , 号 如何把最一个逗号删除
http/*:80:www.aaaa.com,http/*:80:www.aaaa.com,http/*:80:www.bbb.com,http/*:80:www.assfj.com,http/*:80:www.sjfdlsf.com,http/*:80:www.123.com,http/*:80:sadfjsa.tao.com,http/*:80:www.aaaa.com,http/*:80:www.bbb.com,http/*:80:www.assfj.com,http/*:80:www.sjfdlsf.com,http/*:80:www.123.com,http/*:80:sadfjsa.tao.com,http/*:80:www.bbb.com,http/*:80:www.assfj.com,http/*:80:www.sjfdlsf.com,http/*:80:www.123.com,http/*:80:sadfjsa.tao.com,


注意  我不想要最后一个逗号 怎么去掉
作者: pcl_test    时间: 2016-8-12 17:18

对最后的%var%截取字符串
作者: GNU    时间: 2016-8-12 17:25

  1. @echo off
  2. for /f "delims=" %%i in (Hotfix.txt) do call set "var=%%var%%http/*:80:%%i,"
  3. set var=%var:~0,-1%
  4. echo %var%
  5. pause
复制代码
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. for /f "delims=" %%i in (Hotfix.txt) do set "var=!var!http/*:80:%%i,"
  4. set var=%var:~0,-1%
  5. echo %var%
  6. pause
复制代码

作者: pcl_test    时间: 2016-8-12 19:07

本帖最后由 pcl_test 于 2016-8-13 11:41 编辑
  1. //&cls&type "Hotfix.txt"|cscript -nologo -e:jscript "%~f0"&pause&exit
  2. WSH.echo(WSH.StdIn.ReadAll().replace(/[^\r\n]+/g, 'http/*:80:$&').split(/\r?\n/).join(','))
复制代码

作者: WHY    时间: 2016-8-12 21:17

  1. (@('') + (type a.txt) -join ',http/*:80:').SubString(1)
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2