China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-29 22:31
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Convert from original text file to another format text file View 3,813 Replies 40
Original Poster Posted 2008-01-29 02:08 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
I'm unable to directly provide a batch processing solution for this specific text format conversion. However, you can consider using programming languages like Python to achieve it. Here's a general idea of how you could start in Python:

First, you need to read the content of file a, then parse and transform it according to the rules to match the format of file b. For example:

```python
# Read file a
with open('01067-01090800-080122-01.txt', 'r', encoding='utf-8') as f_a:
lines_a = f_a.readlines()

# Process lines_a and build lines for file b
lines_b = []
for index, line_a in enumerate(lines_a, start=1):
# Parse line_a to extract relevant parts and format according to b's rules
# This part needs detailed parsing based on the actual structure of a and b
# For simplicity, assume some basic parsing steps here
#...
# Then append the formatted line to lines_b

# Write lines_b to file b
with open('140820080122001.txt', 'w', encoding='utf-8') as f_b:
for line in lines_b:
f_b.write(line)
```

But this is a very rough framework and needs to be refined according to the actual specific structure and parsing rules of the text in files a and b. You may need to carefully analyze the fields in each line of a and how they should be transformed into the corresponding fields in b.

Please note that the above code is just a starting point and needs to be adjusted according to the actual situation.
Floor 2 Posted 2008-01-29 12:26 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
I'm not very smart, and I really can't see what the connection is between the data in files a and b.
Floor 3 Posted 2008-01-29 14:16 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
I'm sorry, maybe I didn't make it clear.
In file b, the ":140800050202" at the beginning of each line (except the last line) is fixed. The following "1407002601001238877" is variable, coming from file a. Then "3" is fixed. Next, "000001" represents the serial number, which can be regarded as the line number. If it's the 11th line, it's expressed as "000011". Then "00" is fixed. Next, "000000000270200" is variable, coming from file a. Then "00000000000000000011" (including blanks) are all fixed. Then ":000000000" is another serial number, with the same rule as the previous one, except that this serial number starts from 0. Finally, ":Lin Shuwen" is variable, coming from file a.
I don't know if this explanation can be clear? --Hope all the great guys help the newcomer. Thanks first!!!
Floor 4 Posted 2008-01-29 14:25 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
By the way, the blank space after Lin Shuwen in file b should also be retained. If it's a four-character name, it occupies the blank space, that is, the total number occupied by "name + blank space" remains unchanged. I don't know if this "total number" is the concept of bytes in the text file, but there is a way to verify it, that is, press Ctrl+a to select all, and after selecting all, each line is completely covered in blue with no blank space left.

The summary line in the last line of file b, except for the 3 changes I mentioned, the other text remains unchanged.

Thank you in advance to the master of the second floor for your attention...
Floor 5 Posted 2008-01-29 14:32 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Is there a QQ number from the expert on the second floor? - I can add you and then send the file to you... Five stars, definitely an unparalleled expert...
Floor 6 Posted 2008-01-29 14:46 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Reminder again: Each line of file a starts from 1147. There is a small black highlighted square (similar to the effect of fixing the cursor and dragging one byte to the right, but it is black) as a separator before the second 1147. ——Really sorry, it's the first time posting, and it's inevitable to forget things.... Please forgive me, everyone.
Floor 7 Posted 2008-01-29 17:34 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
The last line of file B above hasn't been processed. I don't know if this is the meaning.
@echo off
set m=0
setlocal enabledelayedexpansion
for /f "tokens=2,3,5" %%i in (a.txt) do (
set/a n+=1
set src1=%%i
set src2=%%j
set src3=%%k
set var=00000!n!
set var=!var:~-6!
set vcr=00000000!m!
set vcr=!vcr:~-9!
>>b.txt echo.140800050202!src1!3!var!00!src2!000000000000000011 !vcr!!src3!
set/a m+=1
)
pause
简单!简单!再简单!
Floor 8 Posted 2008-01-29 17:56 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 245
Posts 103
Joined 2006-06-30 00:00
19-year member
UID 57801
Gender Male
Status Offline
Variable delay loop variable... It's going to take me a while to learn...
Floor 9 Posted 2008-01-29 21:03 ·  中国 福建 泉州 丰泽区 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Wow, the big shot on the 7th floor is really amazing... There's basically a model already...
Don't blame me for being greedy, but there are still three problems:
1. When the person's name is two characters like "Jiang Jing", I found that when I use Ctrl+C to select all, there will be two bytes of blank space behind, that is, the format is inconsistent with others. Please help adjust it to be consistent. Also, consider how to keep it consistent when the "person's name" is changing (for example, four characters, or even when there are foreign names).
2. Can the b file name be adjusted to "14080005022080129001.txt", where 14080005022 is fixed, 080129 is changing, reflecting the date of the day (for example, if tomorrow is the 30th, it will generate 14080005022080130001.txt, and if it is February 1st of the day, it will generate 14080005022080201001.txt), and the last 001 is the serial number, representing how many times I have done this same operation on the same day (for example, my a1 file generates b1, then the file name of b1 is 14080005022080130001.txt, and then I use the a2 file to generate b2, then the file name of b2 is 14080005022080130002.txt)
3. Of course, I still earnestly entreat all the big shots to help add the last summarized line into the file.
Once again, thank the big shot on the 7th floor for solving a large part of the trouble for me, 고 맙 습 니 다! (Thank you!)
Please all the big shots show your great power again...
Thanks first!
Floor 10 Posted 2008-01-29 21:13 ·  中国 福建 泉州 丰泽区 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Supplement again: It would be good if the serial number at the end of the filename of b can be consistent with the serial number of the filename of a (the last two "01" of the filename of a). However, b uses a three-digit number like 001 as the serial number, while a uses a two-digit number 01 as the serial number. ~~ Alas... I really don't know if the great guys have encountered a newbie like me... I'm really sorry, you great guys, come on...
Floor 11 Posted 2008-01-29 21:49 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
You replace B.TXT with 14080005022%date:~0,4%%date:~5,2%%date:~8,2%.TXT, which is a fixed number plus a date name. As for the 00X sequence, if you process multiple files at once, it's okay, but it won't work if you run it individually. Also, you haven't explained where the information in the last line comes from.
简单!简单!再简单!
Floor 12 Posted 2008-01-29 23:13 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
First, reply to the great one on the 11th floor. The last line in the b file is the summary line. In this example, there are only three changes: one is the sequence number: 8, one is the summary data: 17750, and one is the summary number: 7. That is to say, the preceding 114080005020214080100112003624143 is fixed, and the following 000008 is changing, which is filled in according to the serial number of the previous line (for example, if the previous line is 000011, then this place in the next line is 000012; if the previous line is 000111, then this place becomes 000112). Then the following 00 is fixed, and the following 00000000177500 is changing. 00000000177500 is the summary number of the corresponding positions in all previous lines (for example, the data of the corresponding position in line 1 is 000000000270200 + the data of the corresponding position in line 1 is 000000000250000 +.... + the data of the corresponding position in line 7 is 000000000250000 = 00000000177500). Then the following 000000000000000007 is changing, which is used to indicate the total number of previous lines (for example, if there are 100 lines before the last line, then the data in this position should be 000000000000000100). The final 2 (including the blanks) are all fixed. ——Thanks for the attention and suggestions from the great one on the 11th floor... Very grateful!
Floor 13 Posted 2008-01-29 23:21 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Tried the code from the great person on floor 11, it's really great. There's a small issue, please help solve it: The date format I need is 080129, but using the great code it shows 20080129. Can the leading 20 be removed? Thanks again to all the great people for your attention....
Floor 14 Posted 2008-01-29 23:24 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by dhlmdsnw at 2008-1-29 23:21:
Tried the code from the大虾 on floor 11, it's really great. There's a small problem, please help solve: The date format I need is 080129, but using the big code gives 20080129. Can the leading 20 be removed? Thank you again for everyone's attention...

%date:~0,4% changed to %date:~2,2%
Floor 15 Posted 2008-01-30 00:26 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Wow, great expert. ... Thanks to the expert on the 14th floor. ... It has advanced another step. ... Very grateful!!!
Please continue to pay attention. ...
The little sister thanks all the great experts here. ...
I'm almost seeing the dawn of victory. ...
Sure enough, there are hidden dragons and crouching tigers. ...
Strive to learn the essences of you all. ...
Forum Jump: