wh123wh123 当前离线
六级士官
Gin_Q 当前离线
五级士官
# -*- coding:gbk -*- a_content = [] b_content = [] a_file = "a.txt" b_file = "b.txt" content_add = "同V" with open(a_file) as fra: a_content = fra.readlines() with open(b_file) as frb: b_content = frb.readlines() for b_line in b_content: if b_line[-1] == "\n": b_line = b_line[0:-1] for index in range(len(a_content)): if a_content[index].find(b_line) != -1: if a_content[index][-1] == "\n": a_content[index] = a_content[index][0:-1] + content_add + "\n" else: a_content[index] = a_content[index][0:-1] + content_add # 覆盖写入 with open(a_file, "w") as fw: fw.writelines(a_content)复制代码
TOP
newswan 当前离线
上尉
@echo off setlocal enableDelayedExpansion set path=%gnupath%;%path% for /f "delims=" %%b in (b.txt) do ( sed.exe ' /%%b/s/$/xxx/ ' -i a.txt )复制代码
for /f "delims=" %%b in (b.txt) do ( sed.exe -r -e ' /\[TIPWORD\]/,/\[/ {/%%b/s/$/xxx/} ' -i a.txt )复制代码
xczxczxcz (Tα酱油路过)当前离线
中尉
$a = 'xxxxx\a.txt'; $b = 'xxxxx\b.txt'; $t = '\xcd\xac\x56' [regex]::Replace(((gc $a -read 0) -join "`n"), "(?is)\[TIPWORD[^\[]+", { $str = $args.Value; (gc $b -read 0) | % { $str = [regex]::Replace($str, "(?s)(?<=\d+)($_=.*?)(\n?)", "$_=$t`$2"); } $str; } ) | sc $a -Force;复制代码