|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『楼 主』:
如何把所有txt文件中第10行第20个数字相加
使用 LLM 解释/回答一下
请问如何把一个目录下所有txt文件中第10行中第20个字符(肯定是阿拉伯数字)都相加起来算出总值显示在cmd窗口中
不知道可以吗谢谢
Last edited by namejm on 2007-2-5 at 10:34 AM ]
May I ask how to sum up the 20th character (which must be an Arabic numeral) in the 10th line of all txt files in a directory and display the total value in the cmd window? I don't know if it's possible, thank you.
Last edited by namejm on 2007-2-5 at 10:34 AM ]
|
|
2006-9-10 00:04 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
把以下代码放到该目录下运行,同时请保证该目录下只存在参与运算的txt文件:
@echo off
set num=0
setlocal enabledelayedexpansion
for %%i in (*.txt) do (
set file=%%i
for /f "tokens=1* delims=:" %%j in ('findstr /n . !file!') do (
set var=%%k
if %%j equ 10 (set num_=!var:~19,1!)&& set /a num=!num!+!num_!
)
)
echo 相加后的结果是: %num%
pause
Last edited by namejm on 2006-9-10 at 06:13 ]
Put the following code to run in this directory, and make sure that only the txt files involved in the operation exist in this directory:
@echo off
set num=0
setlocal enabledelayedexpansion
for %%i in (*.txt) do (
set file=%%i
for /f "tokens=1* delims=:" %%j in ('findstr /n . !file!') do (
set var=%%k
if %%j equ 10 (set num_=!var:~19,1!)&& set /a num=!num!+!num_!
)
)
echo The result after addition is: %num%
pause
Last edited by namejm on 2006-9-10 at 06:13 ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-10 01:13 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
谢谢你,我试运行了你的程序,原来我前面没写清楚,肯定是第10行,但第几个字符我不知道,因为好象这个数要跨过2个或3个字符.
我上传了几个txt文件,里边的数范围是十位数到千位数.谢谢帮我看看
Thank you, I ran your program for trial. Originally, I didn't make it clear before. It must be line 10, but I don't know which character it is, because it seems that this number has to cross 2 or 3 characters.
I uploaded several txt files, and the numbers inside range from ten-digit to thousand-digit. Thank you for helping me take a look
附件
1: 新建文件夹.rar (2006-9-10 01:48, 743 bytes, 下载附件所需积分 1 点
,下载次数: 17)
|
|
2006-9-10 01:48 |
|
|
9527
银牌会员
     努力做坏人
积分 1185
发帖 438
注册 2006-8-28 来自 北京
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
@echo off&setlocal
for %%a in (*.txt) do (set c=)&call :ok "%%a"
:ok
for /f "skip=9 usebackq tokens=*" %%x in (%1) do (
if not defined c set "c=%%x"
call set /a pp=pp+%%c:~19,1%%
goto :eof
)
echo %pp%
用另外一种方法完成!!! 不过不知道效果如何??? 呵呵..........
@echo off&setlocal
for %%a in (*.txt) do (set c=)&call :ok "%%a"
:ok
for /f "skip=9 usebackq tokens=*" %%x in (%1) do (
if not defined c set "c=%%x"
call set /a pp=pp+%%c:~19,1%%
goto :eof
)
echo %pp%
Use another method to complete!!! But I don't know how it works??? Hehe..........
|

我今后在论坛的目标就是做个超级坏人!!! |
|
2006-9-10 01:51 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
呵呵,pip的代码直接就取到第10行的内容,比我那个代码的效率要高得多,没注意到效率问题,是我那个代码的一大缺陷。
Hehe, the code of pip directly gets the content of line 10, which is much more efficient than my code. I didn't notice the efficiency issue, which is a big flaw in my code.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-10 02:03 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by lulala at 2006-9-10 01:48:
谢谢你,我试运行了你的程序,原来我前面没写清楚,肯定是第10行,但第几个字符我不知道,因为好象这个数要跨过2个或3个字符.
我上传了几个txt文件, ...
看了你的txt,发现数字是分列显示的,这个就更容易了,但是我不知道你要第几列的数字相加,请明示。
Originally posted by lulala at 2006-9-10 01:48:
Thank you. I ran your program for trial. I didn't make it clear before. It must be line 10, but I don't know which character. Because it seems that this number spans 2 or 3 characters.
I uploaded several txt files, ...
I read your txt and found that the numbers are displayed in columns. This is even easier, but I don't know which column of numbers you want to add. Please specify.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-10 02:07 |
|
|
9527
银牌会员
     努力做坏人
积分 1185
发帖 438
注册 2006-8-28 来自 北京
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
namejm 兄过谦了,兄在联盟的地位是不可动摇的,我对兄的佩服有如滔滔江水连绵不绝,一发不可收拾!!!
Namejm, you are being too modest. Your position in the union is unshakable. My admiration for you is like a surging river that goes on and on without stopping!
|

我今后在论坛的目标就是做个超级坏人!!! |
|
2006-9-10 02:11 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
谢谢楼上几位兄台
我是想把都相加不管几列几列,如243+1246+21....
Thanks to the several brothers upstairs
I want to add all of them, no matter how many columns, like 243+1246+21....
|
|
2006-9-10 05:49 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
我晕,不管3721,只要是数字都相加?这个超级BT啊。
总得指定哪几列的内容相加的嘛,要不然,你这个操作还有什么意义?
Oh, I'm dizzy. Regardless of 3721, just add all the numbers? This is super BT.
You always have to specify which columns' contents to add. Otherwise, what's the point of your operation?
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-10 06:15 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
也不是不管几列,都相加,我的意思就是说:在我上传的那个压缩包里的txt文件,3种形式都有了,即十位数,百位数,千位数,一个txt文件中第10行有可能是十位数,也可能是百位数,也可能是千位数,但总有一个数,这个数的位置也基本固定,发现几个txt文件中的数的最后一位(个位数)总在一个固定字符位置
如 1.txt 第10行 123
2.txt 第10行 1234
3.txt 第10行 34
上面 个位数3,4,4的位置应该是对齐的
谢谢你的热心帮助!!!:P
It's not that we add up no matter how many columns. I mean, in the txt file in the compressed package I uploaded, there are all three forms, namely ten-digit, hundred-digit, thousand-digit. The 10th line in a txt file may be ten-digit, or hundred-digit, or thousand-digit, but there is always a number, and the position of this number is basically fixed. I found that the last digit (units digit) of the numbers in several txt files is always in a fixed character position.
For example, in 1.txt, the 10th line is 123; in 2.txt, the 10th line is 1234; in 3.txt, the 10th line is 34. The positions of the units digits 3, 4, 4 above should be aligned.
Thank you for your enthusiastic help!!! :P
|
|
2006-9-10 06:37 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
这个可以不管数字在哪个字符位上,你只要告诉我要把哪个列上的数相加就得了——你总不会连列的意思都闹不明白吧,因为我发现你一直没告诉我要处理哪一列上的,而总是在说某个字符位上的。并且你你举例的内容和上传的文本内容不吻合,我无法得知你的真实意思——你还是就你上传的文件内容举例吧。
This can ignore where the number is in the character position, you just need to tell me which column of numbers to add—you can't even not understand the meaning of a column, because I find that you haven't always told me which column to process, but always talking about a certain character position. And the content you exemplified doesn't match the uploaded text content, I can't know your real meaning—you'd better give examples based on the content of the file you uploaded.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-10 06:48 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
|
2006-9-10 07:56 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
你只要告诉我要把哪个列上的数相加就得了 ,数是随机的,有可能是十位数,百位数或千位数则么能确定要哪个列数相加呢?
You just need to tell me which column's numbers to add. The numbers are random, and they might be ten-digit, hundred-digit, or thousand-digit. How can I determine which column's numbers to add?
|
|
2006-9-10 08:00 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
并且你你举例的内容和上传的文本内容不吻合
形式是相同的,只是换个数字而已啊,目录下有这些txt文件,没规定一定要几个是百位数,几个是千位数,几个是个位数,但他们的位置即个位数的位置总在这个txt文件第10行的固定. 到底是固定第几列我也不好数,因为我不知道做程序的时候从哪开始算第一列.
And the content you exemplified does not match the uploaded text content. The form is the same, just changing a number. There are these txt files in the directory. There is no regulation that there must be several hundred-digit numbers, several thousand-digit numbers, and several single-digit numbers, but their position, that is, the position of the single-digit number, is always fixed in the 10th line of this txt file. I can't count exactly which column it is fixed in because I don't know where to start counting the first column when making the program.
|
|
2006-9-10 08:04 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by lulala at 2006-9-10 07:56:
字符位=列
我晕,有这样的等式吗?如果你这样认为的话,那我确实帮不了你。
Originally posted by lulala at 2006-9-12 07:56:
Character position = column
Oh my god, is there such an equation? If you think so, then I really can't help you.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-10 08:16 |
|