中国DOS联盟论坛

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-27 02:18
47,813 topics / 349,918 posts / today 0 new / 48,276 members
DOS批处理 & 脚本技术(批处理室) » [Help] Convert from original text file to another format text file
Printable Version  4,496 / 40
Floor1 dhlmdsnw Posted 2008-01-29 02:08
初级用户 Posts 59 Credits 127
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.
Floor2 HAT Posted 2008-01-29 12:26
版主 Posts 5,017 Credits 9,023
I'm not very smart, and I really can't see what the connection is between the data in files a and b.
Floor3 dhlmdsnw Posted 2008-01-29 14:16
初级用户 Posts 59 Credits 127
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!!!
Floor4 dhlmdsnw Posted 2008-01-29 14:25
初级用户 Posts 59 Credits 127
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...
Floor5 dhlmdsnw Posted 2008-01-29 14:32
初级用户 Posts 59 Credits 127
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...
Floor6 dhlmdsnw Posted 2008-01-29 14:46
初级用户 Posts 59 Credits 127
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.
Floor7 terse Posted 2008-01-29 17:34
银牌会员 Posts 946 Credits 2,404
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
Floor8 flying008 Posted 2008-01-29 17:56
中级用户 Posts 103 Credits 245
Variable delay loop variable... It's going to take me a while to learn...
Floor9 dhlmdsnw Posted 2008-01-29 21:03
初级用户 Posts 59 Credits 127
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!
Floor10 dhlmdsnw Posted 2008-01-29 21:13
初级用户 Posts 59 Credits 127
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...
Floor11 terse Posted 2008-01-29 21:49
银牌会员 Posts 946 Credits 2,404
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.
Floor12 dhlmdsnw Posted 2008-01-29 23:13
初级用户 Posts 59 Credits 127
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!
Floor13 dhlmdsnw Posted 2008-01-29 23:21
初级用户 Posts 59 Credits 127
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....
Floor14 zh159 Posted 2008-01-29 23:24
金牌会员 Posts 1,467 Credits 3,687
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%
Floor15 dhlmdsnw Posted 2008-01-30 00:26
初级用户 Posts 59 Credits 127
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. ...
1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023