标题: [文本处理] 求助 字符后添加顺序数字 批处理 [打印本页]
作者: clsall 时间: 2021-6-19 16:56 标题: 求助 字符后添加顺序数字 批处理
本帖最后由 clsall 于 2021-6-19 17:14 编辑
<smilie smilie_category_id="1" title="/ac" display_order="10" display_in_editor="1">
<image_url>data/assets/smilies/ac.png</image_url>
<image_url_2x></image_url_2x>
<smilie_text>/ac</smilie_text>
</smilie>
<smilie smilie_category_id="1" title="/ac" display_order="10" display_in_editor="1">
<image_url>data/assets/smilies/ac.png</image_url>
<image_url_2x></image_url_2x>
<smilie_text>/ac</smilie_text>
</smilie>
<smilie smilie_category_id="1" title="/ac" display_order="10" display_in_editor="1">
<image_url>data/assets/smilies/ac.png</image_url>
<image_url_2x></image_url_2x>
<smilie_text>/ac</smilie_text>
</smilie>
文本中所有的/ac后面添加顺序数字,感谢各位 感谢
<smilie smilie_category_id="1" title="/ac1" display_order="10" display_in_editor="1">
<image_url>data/assets/smilies/ac1.png</image_url>
<image_url_2x></image_url_2x>
<smilie_text>/ac1</smilie_text>
</smilie>
<smilie smilie_category_id="1" title="/ac2" display_order="10" display_in_editor="1">
<image_url>data/assets/smilies/ac2.png</image_url>
<image_url_2x></image_url_2x>
<smilie_text>/ac2</smilie_text>
</smilie>
<smilie smilie_category_id="1" title="/ac..." display_order="10" display_in_editor="1">
<image_url>data/assets/smilies/ac....png</image_url>
<image_url_2x></image_url_2x>
<smilie_text>/ac...</smilie_text>
</smilie>
作者: newswan 时间: 2021-6-19 18:11
本帖最后由 newswan 于 2021-6-19 19:26 编辑
powershell- $file = "1.txt"
-
- $fc = get-content -raw $file
-
- $i = 0
- while ($fc -match '(?s)(<smilie .*?</smilie>)(.*)')
- {
- $i++
- $s += $matches[1] -replace "ac",("ac" + [string] $i)
- $fc = $matches[2]
- }
- $s + $fc | out-file $file
复制代码
作者: qixiaobin0715 时间: 2021-6-20 09:19
纯批好像也行。将代码和文本文件存为ANSI编码:- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in (test.txt) do (
- set "str=%%a"
- if not "!str:<smilie smilie=!"=="!str!" set /a n+=1
- for %%i in (!n!) do set "str=!str:/ac=/ac%%i!"&echo,!str!
- )
- pause
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |