在文本文档每一行前面加上相同的字符串的方法

方法一:

@echo off
for /f "tokens=* delims=" %%i in ('findstr /n ".*" 1.txt') do (
for /f "tokens=1,* delims=:" %%j in ("%%i") do (
echo train/%%k>>2.txt
)
)
把以上代码存为bat文件,放在1.txt所在目录运行,将输出目标文件2.txt

方法二:

说个非主流的

复制到 excel,前后插单元格,批量处理后,复制回 txt

也就是,直接在excel前面插入单元格,全部写入 ‘train/’,然后直接复制到txt。

方法三:

用python,

text = open("a.txt", "r").read()
text2 = ""

for s in text.split('\n'):
    text2 += "123abc " + s + " 456xyz\n"
print text2

模仿操作即可。

知乎链接http://www.zhihu.com/question/37708379

posted @ 2016-07-29 22:10  静悟生慧  阅读(1338)  评论(0编辑  收藏  举报