标题: [文本处理] 【已解决】BAT批处理怎样判断为纯英文的行其后面追加数字? [打印本页]
作者: elec 时间: 2014-5-26 17:13 标题: 【已解决】BAT批处理怎样判断为纯英文的行其后面追加数字?
本帖最后由 elec 于 2014-7-8 08:14 编辑
一个文本,里面主要为英文。
判断每一行,如果为纯英文(没有数字【0-9】),就在每行后面追加2014?
如何办到??
作者: 522235677 时间: 2014-5-26 19:22
- for /f "delims=" %%a in ('Findstr "^[a-z]*$" 1.txt') do echo %%a2014 >>new.txt
复制代码
作者: elec 时间: 2014-7-7 23:16
回复 2# 522235677
代码测试不成功。未生成new.txt
为啥多了一个1,运行错误和这儿有关?
作者: CrLf 时间: 2014-7-7 23:30
本帖最后由 CrLf 于 2014-7-8 00:27 编辑
多的那个 1 代表 StdOut,不影响输出- @echo off
- (for /f "delims=" %%a in (a.txt) do (
- for /f "tokens=1* delims=0123456789" %%b in ("%%a#") do (
- if %%c#==# (echo %%a2014) else (echo %%a)
- )
- ))>new.txt
复制代码
这用 sed 最合适:- sed "/[0-9]/!s/$/2014/" 1.txt >new1.txt
- ::不换行
-
- sed "/[0-9]/!a2014" 1.txt >new2.txt
- ::换行
复制代码
作者: elec 时间: 2014-7-8 00:01
回复 4# CrLf
为什么您的代码。第一个测试也是不成功?没有任何输出文件。 是保存为bat,双击吧
sed第一段代码成功,所有输出连在一起了。
sed第二段代码不成功,输出一个空文件new2.txt
作者: CrLf 时间: 2014-7-8 00:09
回复 5# elec
已修改
作者: elec 时间: 2014-7-8 00:22
回复 6# CrLf
sed第二个还是出错
您可能没懂我的意思哈。test.txt- 5 died after a missile reportedly struck a smuggling tunnel near Rafah.
- The Israeli military said it
- had hit "terror sites and concealed rocket launchers"
- in 2014 response to rocket and mortar fire from the coastal territory.
- Tensions have risen since a Palestinian youth was killed
- in apparent reprisal for the murder of three Israelis.
- On Sunday, Israeli police said they had arrested 7
- Jewish suspects in connection with the death of Mohammed 90's Abu Khdair last week.
- Yolande Knell reports from Shufat where a mourning 10 for Mohammed
复制代码
2356行没有数字,输出的格式。。- 5 died after a missile reportedly struck a smuggling tunnel near Rafah.
- The Israeli military said it 2014
- had hit "terror sites and concealed rocket launchers" 2014
- in 2014 response to rocket and mortar fire from the coastal territory.
- Tensions have risen since a Palestinian youth was killed 2014
- in apparent reprisal for the murder of three Israelis.2014
- On Sunday, Israeli police said they had arrested 7
- Jewish suspects in connection with the death of Mohammed 90's Abu Khdair last week.
- Yolande Knell reports from Shufat where a mourning 10 for Mohammed
复制代码
作者: CrLf 时间: 2014-7-8 00:27
回复 7# elec
好吧,原来“纯英文”是有标点的...已修改
作者: elec 时间: 2014-7-8 08:13
回复 8# CrLf
结果只有new1正确
new1.txt- 5 died after a missile reportedly struck a smuggling tunnel near Rafah.
- The Israeli military said it 2014
- had hit "terror sites and concealed rocket launchers" 2014
- in 2014 response to rocket and mortar fire from the coastal territory.
- Tensions have risen since a Palestinian youth was killed 2014
- in apparent reprisal for the murder of three Israelis.2014
- On Sunday, Israeli police said they had arrested 7
- Jewish suspects in connection with the death of Mohammed 90's Abu Khdair last week.
- Yolande Knell reports from Shufat where a mourning 10 for Mohammed
复制代码
new.txt 第一行有一个5,后面不应该加2014- 5 died after a missile reportedly struck a smuggling tunnel near Rafah.2014
- The Israeli military said it 2014
- had hit "terror sites and concealed rocket launchers" 2014
- in 2014 response to rocket and mortar fire from the coastal territory.
- Tensions have risen since a Palestinian youth was killed 2014
- in apparent reprisal for the murder of three Israelis.2014
- On Sunday, Israeli police said they had arrested 7
- Jewish suspects in connection with the death of Mohammed 90's Abu Khdair last week.
- Yolande Knell reports from Shufat where a mourning 10 for Mohammed
复制代码
new2.txt 2014不在下一行- 5 died after a missile reportedly struck a smuggling tunnel near Rafah.
- The Israeli military said it
- 2014
- had hit "terror sites and concealed rocket launchers"
- 2014
- in 2014 response to rocket and mortar fire from the coastal territory.
- Tensions have risen since a Palestinian youth was killed
- 2014
- in apparent reprisal for the murder of three Israelis.
- 2014
- On Sunday, Israeli police said they had arrested 7
- Jewish suspects in connection with the death of Mohammed 90's Abu Khdair last week.
- Yolande Knell reports from Shufat where a mourning 10 for Mohammed
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |