![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-15 12:59 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » How to sum the 20th number in the 10th line of all txt files |
| Printable Version 4,225 / 20 |
| Floor1 lulala | Posted 2006-09-10 00:04 |
| 初级用户 Posts 17 Credits 44 | |
|
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 ] |
|
| Floor2 namejm | Posted 2006-09-10 01:13 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
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:
[ Last edited by namejm on 2006-9-10 at 06:13 ] |
|
| Floor3 lulala | Posted 2006-09-10 01:48 |
| 初级用户 Posts 17 Credits 44 | |
|
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 Attachments 新建文件夹.rar (743 bytes) |
|
| Floor4 9527 | Posted 2006-09-10 01:51 |
| 银牌会员 Posts 438 Credits 1,185 From 北京 | |
|
@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.......... |
|
| Floor5 namejm | Posted 2006-09-10 02:03 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
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.
|
|
| Floor6 namejm | Posted 2006-09-10 02:07 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
Originally posted by lulala at 2006-9-10 01:48: 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. |
|
| Floor7 9527 | Posted 2006-09-10 02:11 |
| 银牌会员 Posts 438 Credits 1,185 From 北京 | |
|
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!
|
|
| Floor8 lulala | Posted 2006-09-10 05:49 |
| 初级用户 Posts 17 Credits 44 | |
|
Thanks to the several brothers upstairs
I want to add all of them, no matter how many columns, like 243+1246+21.... |
|
| Floor9 namejm | Posted 2006-09-10 06:15 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
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? |
|
| Floor10 lulala | Posted 2006-09-10 06:37 |
| 初级用户 Posts 17 Credits 44 | |
|
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 |
|
| Floor11 namejm | Posted 2006-09-10 06:48 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
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.
|
|
| Floor12 lulala | Posted 2006-09-10 07:56 |
| 初级用户 Posts 17 Credits 44 | |
| Floor13 lulala | Posted 2006-09-10 08:00 |
| 初级用户 Posts 17 Credits 44 | |
|
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?
|
|
| Floor14 lulala | Posted 2006-09-10 08:04 |
| 初级用户 Posts 17 Credits 44 | |
|
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.
|
|
| Floor15 namejm | Posted 2006-09-10 08:16 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
Originally posted by lulala at 2006-9-12 07:56: Oh my god, is there such an equation? If you think so, then I really can't help you. |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |