[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理怎样为所有TXT文件的每行文字添加HTML换行标记?

如题,当前目录下有几十个TXT文件,每个TXT内容都是不同的纯文本格式文章,现在想为所有的TXT文件的每一个段落添加<p></p>的标记,不知批处理该怎么写?

举个例子,下面的是其中一个TXT文件原始内容:

In spite to the fact that open gastric bypass surgery is still often done an increasing quantity of surgeons are starting to adopt the laparoscopic approach and, although this requires quite a lot of training and expertise on the surgeon's part, there are several advantages to this approach. Take a look at a couple of:

1. As just about 5 tiny incisions are made the healing time following surgery is greatly reduced, as is the chance of infection and of suffering a hernia.

2. There's substantially less post-operative pain and the little discomfort that is present requirements only mild painkillers this kind of as tylenol and codeine.

3. Laparoscopic surgery enables greater precision since surgery is performed under magnification and the surgeon can see details that aren't visible during open surgery.

4. As laprascopic surgery is quicker than traditional open surgery the patient spends less time in surgery and requirements much less anesthesia, leading to fewer anesthesia-related complications.

5. As patients are on their feet rapidly there is less risk of blood clots, bed sores, pneumonia and other complications normally associated with immobility.


批处理运行后,希望得到的结果是下面这样:

<P>In spite to the fact that open gastric bypass surgery is still often done an increasing quantity of surgeons are starting to adopt the laparoscopic approach and, although this requires quite a lot of training and expertise on the surgeon's part, there are several advantages to this approach. Take a look at a couple of:</P>

<P>1. As just about 5 tiny incisions are made the healing time following surgery is greatly reduced, as is the chance of infection and of suffering a hernia.</P>

<P>2. There's substantially less post-operative pain and the little discomfort that is present requirements only mild painkillers this kind of as tylenol and codeine.</P>

<P>3. Laparoscopic surgery enables greater precision since surgery is performed under magnification and the surgeon can see details that aren't visible during open surgery.</P>

<P>4. As laprascopic surgery is quicker than traditional open surgery the patient spends less time in surgery and requirements much less anesthesia, leading to fewer anesthesia-related complications.</P>

<P>5. As patients are on their feet rapidly there is less risk of blood clots, bed sores, pneumonia and other complications normally associated with immobility.</P>

[ 本帖最后由 zxzl 于 2010-7-2 13:13 编辑 ]

  1. sed -i "/^$/b;s#^#<P>#;s#$#</P>#" 1.txt
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

感谢 Batcher老大,这个代码可以实现,假如不用SED的话,用批处理能否实现呢?

[ 本帖最后由 zxzl 于 2010-7-2 13:38 编辑 ]

TOP

  1. @for /f "delims=" %%i in ('type 1.txt') do (echo ^<P^>%%i>>a.txt)
复制代码
---学无止境---

TOP

  1. @echo off
  2. for %%a in (*.txt) do (
  3.     cd.>temp
  4.     for /f "tokens=1* delims=:" %%b in ('findstr /n .* %%a') do (
  5.         if "%%c" neq "" (
  6.            echo ^<p^>%%c^</p^>>>temp
  7.            ) else (
  8.            echo.>>temp
  9.         )
  10.     )
  11.     del /q %%a&ren temp %%a
  12. )
  13. del /q temp&echo 搞定!
  14. pause>nul
复制代码

[ 本帖最后由 batman 于 2010-7-2 15:52 编辑 ]
***共同提高***

TOP

返回列表