|
xycoordinate
中级用户
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『楼 主』:
文本"纵列"如何转换为"横行"?
看第5楼
现有txt文件,是由findstr命令得到的
[QUOTE]
20070101.txt: MEQ 6228770015000125335
20070102.txt: MEQ 62232754000318918
20070102.txt: 10:48 MEQ ACCEPTED
20070102.txt:AMOUNT=50.00
20070102.txt: MTR 62232754000318918
20070102.txt: 10:48 MTR ACCEPTED
20070104.txt: MEQ 6228790915000100566
20070104.txt: 09:26 MEQ ACCEPTED
20070104.txt:AMOUNT=100.00
20070104.txt: MTR 6228790915001000566
20070104.txt: 09:26 MTR ACCEPTED
20070104.txt: MEQ 6228790915001000566
20070104.txt: 09:27 MEQ ACCEPTED
20070105.txt: MEQ 6228791915000011110
20070105.txt: 09:04 MEQ ACCEPTED
20070105.txt:AMOUNT=11.20
20070105.txt: MTR 6228791915000111110
20070105.txt: 09:05 MTR ACCEPTED
像
20070102.txt:AMOUNT=50.00
20070102.txt: MTR 62232754000318918
20070102.txt: 10:48 MTR ACCEPTED
为完整1笔交易!
如何用DOS命令过滤出来,生成文本:
DATE CARD AMOUNT
20070102 62232754000318918 50.00
20070104 6228790915000100566 100.00
......
[ Last edited by xycoordinate on 2007-3-4 at 08:21 AM ]
|
|
2007-3-2 08:33 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
2 楼』:
你着色有问题……
如果你:
20070101.txt: MEQ 6228770015000025335
20070102.txt: MEQ 62232754000308918
20070102.txt: 10:48 MEQ ACCEPTED
20070102.txt:AMOUNT=50.00
20070102.txt: MTR 62232754000308918
20070102.txt: 10:48 MTR ACCEPTED
20070104.txt: MEQ 6228790915000000566
20070104.txt: 09:26 MEQ ACCEPTED
20070104.txt:AMOUNT=100.00
20070104.txt: MTR 6228790915000000566
20070104.txt: 09:26 MTR ACCEPTED
20070104.txt: MEQ 6228790915000000566
20070104.txt: 09:27 MEQ ACCEPTED
20070105.txt: MEQ 6228791915000000110
20070105.txt: 09:04 MEQ ACCEPTED
20070105.txt:AMOUNT=11.20
20070105.txt: MTR 6228791915000000110
20070105.txt: 09:05 MTR ACCEPTED
你看到什么规律了么?
for 分割后,AMOUNT存在那么后2行的数据就有用。
|
|
2007-3-2 11:04 |
|
|
namejm
荣誉版主
batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
|
2007-3-2 12:24 |
|
|
xycoordinate
中级用户
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第
4 楼』:
Quote: | Originally posted by namejm at 2007-3-1 11:24 PM:
可以试试下面的代码:
[code]
@echo off
setlocal enabledelayedexpansion
echo DATE CARD AMOUNT
for /f "tokens=1,2* delims== " %%i in ( ... |
|
斑竹:
您能给XD解释一二吗?
主要是flag看不懂!!!
[ Last edited by xycoordinate on 2007-3-2 at 09:15 AM ]
|
|
2007-3-2 21:43 |
|
|
xycoordinate
中级用户
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第
5 楼』:
findstr命令导出的文本,现在改变了一点:
Quote: | ncrlog\15615\20070101.txt:COM MOBILE:13965229365
ncrlog\15615\20070102.txt:COM MOBILE:13855573825
ncrlog\15615\20070102.txt:AMOUNT=50.00
ncrlog\15615\20070102.txt: MTR 62232754000318918
ncrlog\15615\20070102.txt: 10:48 MTR ACCEPTED
ncrlog\15615\20070104.txt:UNI MOBILE: 13305555353
ncrlog\15615\20070104.txt:AMOUNT=100.00
ncrlog\15615\20070104.txt: MTR 6228790915001200566
ncrlog\15615\20070104.txt: 09:26 MTR ACCEPTED
ncrlog\15615\20070112.txt:WATER:10213809
ncrlog\15615\20070112.txt:AMOUNT=9.60
ncrlog\15615\20070112.txt: MTR 6228791915000044011
ncrlog\15615\20070112.txt: 10:34 MTR ACCEPTED
ncrlog\15615\20070112.txt:GAS: 2009218582
ncrlog\15615\20070112.txt:AMOUNT=21.0
ncrlog\15615\20070112.txt: MTR 6228791915000011011
ncrlog\15615\20070112.txt: 10:36 MTR ACCEPTED
ncrlog\15615\20070126.txt:TELEPHONE:2741779
ncrlog\15615\20070126.txt:AMOUNT=29.00
ncrlog\15615\20070126.txt: MTR 6228770015000211461
ncrlog\15615\20070126.txt: 13:42 MTR ACCEPTED
ncrlog\15606\20070130.txt:ELEC: 40103644
ncrlog\15606\20070130.txt:AMOUNT=214.81
ncrlog\15606\20070130.txt: MTR 62232754000661168
ncrlog\15606\20070130.txt: 16:41 MTR ACCEPTED |
|
总共有6个交易TYPE
UNI MOBILE
COM MOBILE
TELEPHONE
GAS
WATER
ELEC
只有UNI MOBILE后面冒号(:)与CUSTOM_NO之间有空格!
DATE TYPE CUSTOM_NO CARD AMOUNT
20070102 COM MOBILE 13855573825 62232754000312918 50.00
20070104 UNI MOBILE 13305555353 6228790915001200566 100.00
。。。。。。
[ Last edited by xycoordinate on 2007-3-3 at 09:04 PM ]
|
|
2007-3-2 21:45 |
|
|
ccwan
金牌会员
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第
6 楼』:
应该没有什么问题吧,namejm的代码能够完成你的目的。修改一下好了。
|
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-3-2 22:01 |
|
|
xycoordinate
中级用户
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第
7 楼』:
Quote: | Originally posted by ccwan at 2007-3-2 09:01 AM:
应该没有什么问题[/col ... |
|
他写得太深奥了,我根本看不懂,怎么修改呀!?
[ Last edited by xycoordinate on 2007-3-2 at 10:11 AM ]
|
|
2007-3-2 22:05 |
|
|
ccwan
金牌会员
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第
8 楼』:
你的要求怎么一直在改变啊?我刚刚完成了你的上一个要求你又更新了。
|
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-3-2 23:22 |
|
|
ccwan
金牌会员
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第
9 楼』:
希望你不会再改变要求了。^_^
不行,格式有些偏差,等我再改改。
你的COM MOBILE:13855513825,冒号后没有空格,
UNI MOBILE: 13335555353,冒号后有空格,容易错误,不知是否你的疏忽?
[ Last edited by ccwan on 2007-3-2 at 11:33 PM ]
|
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-3-2 23:28 |
|
|
xycoordinate
中级用户
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第
10 楼』:
Quote: | Originally posted by ccwan at 2007-3-2 10:28:
希望你不会再改变要求了。^_^
不行,格式有些偏差,等我再改改。
你的COM MOBILE:13855513825,冒号后没有空格,
UNI MOBILE: 13335555353,冒号后有空格 ... |
|
这是ATM的流水日志,我用findstr命令过滤生成的就是这样!
可能是ATM厂家在编写程序时的疏忽!!
谢谢DG!
好眼力呀!
|
|
2007-3-2 23:48 |
|
|
ccwan
金牌会员
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第
11 楼』:
这次的代码一定行了。代码如下
@echo off
setlocal enabledelayedexpansion
echo DATE TYPE CUSTOM_NO CARD AMOUNT
for /f "tokens=1,2,3 delims== " %%i in (test.txt) do (
if !flag! equ 2 (
echo !name! !TYPE! !CUSTOM_NO! !CARD! !AMOUNT!
set flag=
)
if !flag! equ 1 (
set CARD=%%k
set CARD=!CARD:~0,19!
set flag=2
)
set str=%%i
set var=%%j
if "!var:~0,3!"=="MOB" (
set TYPE=!str:~-3,3! !var:~0,6!
set CUSTOM_NO=!var:~-11,11!
if "!TYPE:~0,3!"=="UNI" set CUSTOM_NO=%%k
)
if "!var:~-3,1!"=="." (
set name=%%~ni
set AMOUNT=%%j
set flag=1
)
)
pause 考虑到格式可能不整齐,附上附件
附件
1: test.rar (2007-3-2 23:53, 417 bytes, 下载附件所需积分 1 点
,下载次数: 6)
|
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-3-2 23:53 |
|
|
xycoordinate
中级用户
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第
12 楼』:
@echo off
setlocal enabledelayedexpansion
echo DATE TYPE CUSTOM_NO CARD AMOUNT
for /f "tokens=1,2,3 delims== " %%i in (test.txt) do (
if !flag! equ 2 (
echo !name! !TYPE! !CUSTOM_NO! !CARD! !AMOUNT!
set flag=
)
if !flag! equ 1 (
set CARD=%%k
set CARD=!CARD:~0,19!
set flag=2
)
set str=%%i
set var=%%j
if "!var:~0,3!"=="MOB" (
set TYPE=!str:~-3,3! !var:~0,6!
set CUSTOM_NO=!var:~-11,11!
if "!TYPE:~0,3!"=="UNI" set CUSTOM_NO=%%k
)
if "!var:~-3,1!"=="." (
set name=%%~ni
set AMOUNT=%%j
set flag=1
)
)
红色的地方需要修改,
总共有6个交易TYPE
UNI MOBILE
COM MOBILE
TELEPHONE
GAS
WATER
ELEC
只有UNI MOBILE后面冒号(:)与CUSTOM_NO之间有空格!
呜呜呜。。。。。。
我又犯错了!
ncrlog\15615\20070112.txt:WATER:10213809
ncrlog\15615\20070112.txt:AMOUNT=9.60
ncrlog\15615\20070112.txt: MTR 6228791915000011011
ncrlog\15615\20070112.txt: 10:34 MTR ACCEPTED
ncrlog\15615\20070112.txt:GAS: 2009218582
ncrlog\15615\20070112.txt:AMOUNT=21.0
ncrlog\15615\20070112.txt: MTR 6228791915000011011
ncrlog\15615\20070112.txt: 10:36 MTR ACCEPTED
ncrlog\15615\20070126.txt:TELEPHONE:2761779
ncrlog\15615\20070126.txt:AMOUNT=29.00
ncrlog\15615\20070126.txt: MTR 6228770015000121461
ncrlog\15615\20070126.txt: 13:42 MTR ACCEPTED
ncrlog\15606\20070130.txt:ELEC: 40103644
ncrlog\15606\20070130.txt:AMOUNT=214.81
ncrlog\15606\20070130.txt: MTR 62232754000121168
ncrlog\15606\20070130.txt: 16:41 MTR ACCEPTED
这次不好麻烦DX了,我只好自己更改了!
[ Last edited by xycoordinate on 2007-3-3 at 09:04 PM ]
|
|
2007-3-3 00:46 |
|
|
xycoordinate
中级用户
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第
13 楼』:
165.txt
Quote: | ncrlog\15600\20070111.txt:COM MOBILE:13705553116
ncrlog\15600\20070111.txt:AMOUNT=100.00
ncrlog\15600\20070111.txt: MTR 62232754000617668
ncrlog\15600\20070111.txt: 15:04 MTR ACCEPTED
ncrlog\15615\20070104.txt:UNI MOBILE: 13305555353
ncrlog\15615\20070104.txt:AMOUNT=100.00
ncrlog\15615\20070104.txt: MTR 6228790915002300566
ncrlog\15615\20070104.txt: 09:26 MTR ACCEPTED
ncrlog\15600\20070109.txt:TELEPHONE:2212834
ncrlog\15600\20070109.txt:AMOUNT=73.00
ncrlog\15600\20070109.txt: MTR 62287909150000112760
ncrlog\15600\20070109.txt: 10:39 MTR ACCEPTED
ncrlog\15615\20070112.txt:WATER:10213809
ncrlog\15615\20070112.txt:AMOUNT=9.60
ncrlog\15615\20070112.txt: MTR 6228791915001100011
ncrlog\15615\20070112.txt: 10:34 MTR ACCEPTED
ncrlog\15606\20070130.txt:ELEC: 40103644
ncrlog\15606\20070130.txt:AMOUNT=214.81
ncrlog\15606\20070130.txt: MTR 62232754000623168
ncrlog\15606\20070130.txt: 16:41 MTR ACCEPTED
ncrlog\15615\20070112.txt:GAS: 2009218582
ncrlog\15615\20070112.txt:AMOUNT=21.0
ncrlog\15615\20070112.txt: MTR 6228791915000110011
ncrlog\15615\20070112.txt: 10:36 MTR ACCEPTED |
|
test.bat
Quote: | @echo off
setlocal enabledelayedexpansion
echo DATE TYPE CUSTOM_NO CARD AMOUNT
for /f "tokens=1,2,3 delims== " %%i in (%1) do (
if !flag! equ 2 (
echo !name! !TYPE! !CUSTOM_NO! !CARD! !AMOUNT!
set flag=
)
if !flag! equ 1 (
set CARD=%%k
rem set CARD=!CARD:~0,19!
set flag=2
)
set str=%%i
set var=%%j
rem MOBILE
if "!var:~0,6!"=="MOBILE" (
set TYPE=!str:~-3,3! MOBILE
set CUSTOM_NO=!var:~-11!
if "!TYPE:~0,3!"=="UNI" set CUSTOM_NO=%%k
)
rem +++++++++++++++++++++++++++++
rem TELEPHONE
if "!str:~-17,9!"=="TELEPHONE" (
set TYPE=TELEPHONE
set CUSTOM_NO=!str:~-7!
)
rem WATER
if "!str:~-14,5!"=="WATER" (
set TYPE=WATER
set CUSTOM_NO=!str:~-8!
)
rem ELEC
if "!str:~-5,4!"=="ELEC" (
set TYPE=ELEC
set CUSTOM_NO=!var!
)
rem GAS
if "!str:~-4,3!"=="GAS" (
set TYPE=GAS
set CUSTOM_NO=!var!
)
rem +++++++++++++++++++++++++++++
if "!var:~-3,1!"=="." (
set name=%%~ni
set AMOUNT=%%j
set flag=1
)
) |
|
CMD:
E:\>test.bat 156.txt
DATE TYPE CUSTOM_NO CARD AMOUNT
20070111 COM MOBILE 13785553216 62232754000719668 100.00
20070104 UNI MOBILE 13305555353 6228790915000000566 100.00
20070109 TELEPHONE 2212834 6228790915012002760 73.00
20070112 WATER 10213809 6228791915000110011 9.60
20070130 ELEC 40103644 62232754000623168 214.81
为什么呀?
就GAS项目不显示???
大家能帮我看看吗?
[ Last edited by xycoordinate on 2007-3-3 at 10:01 PM ]
|
|
2007-3-3 04:06 |
|
|
xycoordinate
中级用户
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第
14 楼』:
靠!
原来GAS的AMOUNT格式都是“**.*”
ncrlog\15615\20070112.txt:GAS: 2009218582
ncrlog\15615\20070112.txt:AMOUNT=21.0
ncrlog\15615\20070112.txt: MTR 6228791915000000011
ncrlog\15615\20070112.txt: 10:36 MTR ACCEPTED
只要在test.bat里加一点,就OK了!
if "!var:~-2,1!"=="." (
set name=%%~ni
set AMOUNT=%%j
set flag=1
)
万分感谢:
namejm
ccwan
[ Last edited by xycoordinate on 2007-3-2 at 04:38 PM ]
|
|
2007-3-3 05:36 |
|
|
xycoordinate
中级用户
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第
15 楼』:
探讨1
test.bat
Quote: | @echo off
setlocal enabledelayedexpansion
echo DATE TYPE CUSTOM_NO CARD AMOUNT
for /f "tokens=1,2,3 delims==, " %%i in (%1) do (
if !flag! equ 2 (
echo !name! !TYPE! !CUSTOM_NO! !CARD! !AMOUNT!
set flag=
echo 1 %%i %%j %%k
)
if !flag! equ 1 (
set CARD=%%k
set flag=2
echo 2 %%i %%j %%k
)
set str=%%i
set var=%%j
rem MOBILE
if "!var:~0,6!"=="MOBILE" (
set TYPE=!str:~-3,3! MOBILE
set CUSTOM_NO=!var:~-11!
echo 3 %%i %%j %%k
)
if "!var:~-3,1!"=="." (
set name=%%~ni
set AMOUNT=%%j
set flag=1
echo 4 %%i %%j %%k
)
) |
|
111.txt
Quote: | ncrlog\15600\20070111.txt:COM MOBILE:13705553216
ncrlog\15600\20070111.txt:AMOUNT=100.00
ncrlog\15600\20070111.txt: MTR 62232754000719668
ncrlog\15600\20070111.txt: 15:04 MTR ACCEPTED |
|
E:\>testmiddle.bat 111.txt >111new.txt
111new.txt
Quote: | DATE TYPE CUSTOM_NO CARD AMOUNT
3 ncrlog\15600\20070111.txt:COM MOBILE:13705553216
4 ncrlog\15600\20070111.txt:AMOUNT 100.00
2 ncrlog\15600\20070111.txt: MTR 62232754000719668
20070111 COM MOBILE 13705553216 62232754000719668 100.00
1 ncrlog\15600\20070111.txt: 15:04 MTR |
|
111new.txt显示的顺序与111.txt的一致.
for命令是一行一行扫描文本!
现在探讨一下,执行test.bat时的步骤:
第1步:
if "!var:~0,6!"=="MOBILE" (
set TYPE=!str:~-3,3! MOBILE
set CUSTOM_NO=!var:~-11!
)
第2步:
if "!var:~-3,1!"=="." (
set name=%%~ni
set AMOUNT=%%j
set flag=1
)
第3步:
if !flag! equ 1 (
set CARD=%%k
set flag=2
)
第4步:
if !flag! equ 2 (
echo !name! !TYPE! !CUSTOM_NO! !CARD! !AMOUNT!
set flag=
)
[ Last edited by xycoordinate on 2007-3-3 at 10:43 AM ]
|
|
2007-3-3 10:07 |
|