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:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Convert from original text file to another format text file View 3,815 Replies 40
Floor 16 Posted 2008-01-30 00:54 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Dear everyone, come on... Who can help me with the name problem and the summary row problem in the last line... Little sister is eagerly looking forward...
Floor 17 Posted 2008-01-30 02:33 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Because the problem of Chinese and English spaces and personal names has not been solved
@echo off
set m=0
set psrc=0
setlocal enabledelayedexpansion
for /f "tokens=2,3,5" %%i in (a01.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!
for /f "delims=0 tokens=*" %%a in ("!src2!") do set/a psrc=!psrc!+%%a
>>14080005022%date:~2,2%%date:~5,2%%date:~8,2%.txt echo.140800050202!src1!3!var!00!src2!000000000000000011 !vcr!!src3!
set/a m+=1

)
set psrc=000000000000000%psrc%
set scr=00000000000000000%n%2
set/a n+=1
set var=00000%n%
>>14080005022%date:~2,2%%date:~5,2%%date:~8,2%.txt echo.114080005020214080100112003624143%var:~-6%%psrc:~-16%%scr:~-19%
pause

[ Last edited by terse on 2008-1-30 at 03:05 AM ]
简单!简单!再简单!
Floor 18 Posted 2008-01-30 13:45 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
First, thank you to大虾 terse for your great help. I haven't tried it yet, but I'm very grateful just to see that you replied to my post as soon as I came back!

Regarding the personal name issue, if we first don't consider foreign personal names, that is, all are in Chinese, can it be solved? -- Because in actual operation, I haven't encountered the operation of foreign personal names yet, it's just something I thought of. -- If only Chinese personal names can be operated, please let the great one post the code for me first.

Thank you again, big shot terse!!!
Floor 19 Posted 2008-01-30 14:44 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
The code modified by terse is as follows:

@echo off
set m=0
set psrc=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!
for /f "delims=0 tokens=*" %%a in ("!src2!") do set/a psrc=!psrc!+%%a
>>140800050%date:~0,4%%date:~5,2%%date:~8,2%001.txt echo.2140800050202!src1!3!var!00!src2!000000000000000011 !vcr!!src3!
set/a m+=1

)
set psrc=000000000000000%psrc%
set scr=00000000000000000%n%2
set/a n+=1
set var=00000%n%
>>140800050%date:~0,4%%date:~5,2%%date:~8,2%001.txt echo.114080005020214080100112003624143%var:~-6%%psrc:~-16%%scr:~-19%
pause

After testing, the main problems are as follows:
1. The number of bytes of "name + subsequent blanks" is insufficient. The expected result is: when "name + subsequent blanks" is all selected and pasted into a cell in Excel, and the LEN function is used for verification, if the name has two characters, the return value of LEN for "name + subsequent blanks" is 51; if the name has three characters, the return value of LEN is 50; if the name has four characters, the return value of LEN is 49. However, with the original code, if the name has two characters, the return value of LEN for "name + subsequent blanks" is 16; if the name has three characters, the return value is 17. There is a large difference.
2. For the last summary line, the number of blanks required after the last data 2, as indicated by the return value of the LEN function in Excel, is 82 bytes. However, the number of blanks generated by the original code is only 47, which is also a large difference.

Finally, there is also the issue of name processing that needs to be improved with more help.

After all these details are processed, the generated file should have all lines fully filled with blue when Ctrl+A is used to select all, with no blanks in each line.
Please continue to improve this code!
Thank you very much here!!!
Floor 20 Posted 2008-01-30 21:17 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Reform again, not sure if it will work?
@echo off
set m=0
set psrc=0
set len=
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!
for /f "delims=0 tokens=*" %%a in ("!src2!") do set/a psrc=!psrc!+%%a
for /f "skip=1 delims=:" %%x in ('^(echo "!src3!"^&echo.^)^|findstr /o ".*"') do set/a l=63-%%x-5
call :loop !l!
>>140800050%date:~0,4%%date:~5,2%%date:~8,2%001.txt echo.2140800050202!src1!3!var!00!src2!000000000000000011 !vcr!!src3!
set/a m+=1
)
set psrc=000000000000000%psrc%
set scr=00000000000000000%n%2
set/a n+=1
set var=00000%n%
>>140800050%date:~0,4%%date:~5,2%%date:~8,2%001.txt echo.114080005020214080100112003624143%var:~-6%%psrc:~-16%%scr:~-19%%len:~0,35%
pause
:loop
set/a mn+=1
set src3=%src3%
if %1 neq %mn% goto loop
set mn=
简单!简单!再简单!
Floor 21 Posted 2008-01-30 21:32 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Wow... Yeah yeah yeah...
Great god terser, I love you to death! ——Yeah yeah yeah...
There's nothing to say, just a word of thanks... I have something to say... Thank you very much...고 맙 습 니 다 !
That's great... My admiration for you is really like a roaring river, endless... Resounding... Wow... It's simply amazing... Yaya...
——But I don't know if it will end in tears. I'll try it at the company tomorrow. Hehe... I have to deal with such things every day. So many... I'm really grateful!... Long live the great god...!!!
Floor 22 Posted 2008-01-30 21:39 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Wow, if tomorrow I can do it in one second with a double-click, I don't know what kind of eyes those people will have on me. Will they also look up to me like the rolling Yangtze River water, endless... I'm even drooling when thinking about it... Hehe... Dude terse, you don't mind me showing off a little in front of my colleagues, right. Hehe. Of course I don't dare to talk nonsense on the forum. Hehe. Yeah yeah yeah... Success. Success... Today I can eat well, sleep well, and go shopping well... The biggest credit goes to you!
Also, I want to thank all the great guys who followed this thread. 감사합니다! (Thank you!)...
La la la...
Floor 23 Posted 2008-01-30 21:44 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Hello, Mr. tersely. I quietly tell you that I still have an unsolved post on the forum... You see, can you take a two-day break... and then take a look at my side again... Hey... I'm really embarrassed... The title of the post is "Delete special characters in text files but keep the format unchanged", it has been posted for a day or two, and no one has given a framework... Of course you should have a good rest... Looking forward to it... Hehe... http://www.cn-dos.net/forum/viewthread.php?tid=37424&fpage=1&highlight=
Floor 24 Posted 2008-01-30 21:51 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Oh my goodness, I'm so overjoyed that I forgot to ask: Dear terse, does your code support foreign names?
Floor 25 Posted 2008-01-30 21:55 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Originally posted by dhlmdsnw at 2008-1-30 21:51:
Oh my god, I'm so happy I've lost all sense of proportion. Oh, I forgot to ask: Mr. terse, does your code support foreign names?

You can give it a try. It should be okay.
简单!简单!再简单!
Floor 26 Posted 2008-01-30 21:57 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Seriously, big shot. I only learned some of the easiest VBA and had already written the code, but then I thought, why not be more straightforward? Later, I flipped through a lot of materials and roughly learned that I could directly convert it through batch processing... But after reading some batch processing teaching materials... I felt that it would take a lot more time to solve. So I came to this forum... By studying your code... Especially step by step to solve my problems... I learned a lot of useful things... I will study further... Thank you big shot's support!!!
Floor 27 Posted 2008-01-30 22:20 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Terse: After testing: The test samples are like: Pandit Singh, Tom Marvolo Riddle, Tripathi Singh. The Chinese names are all okay. If it's a foreign name, after conversion, it becomes Tom, and the rest are gone, blank... It's okay... In the future, I will improve Terse's model through hard study, so you don't need to worry... There has to be a little homework left for my junior to have something to do... If everything is done by you personally, that's not good... Experts should be used on the key points. Hehe... When you are free after resting, you must go to my other post to take a look... Thanks first!... Hehe...
Floor 28 Posted 2008-01-31 12:27 ·  中国 福建 福州 联通
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
Big guy, it's so strange... After I double-clicked your code... there's no reaction at all? And the file 14080005020080131001.txt wasn't generated. It's really strange, nothing happened? Is there something wrong with my computer... At home I'm using XP, and at the company I'm using 2000. ——I first used a batch script, the code in it: copy *.txt /b a.txt /b. To summarize and generate an a.txt file, and then used the big guy's code, but nothing happened after double-clicking? ——Big guy, help take a look again...
Floor 29 Posted 2008-01-31 22:12 ·  中国 福建 泉州 电信
初级用户
★★
Credits 127
Posts 59
Joined 2008-01-29 01:05
18-year member
UID 109744
Status Offline
I finally understand... It turns out my original file has a large number of lines, and it takes nearly 15 seconds to process... and then it's finally generated... Alas, I'm really confused, I'm someone with no foundation...

But, big shot, there's still a variable factor, please help me solve it...

The problem is: In each line of file b (except the last line), the preceding "140800050202" is fixed, and the following "1407002601001238877" is variable, which comes from file a. But if the last part of this number in file a has a non-numeric symbol like an asterisk (like "1407002601001238877*"), please help remove it, not replace it with a blank, and not shift the following blanks forward. But actually delete one byte. Is that okay? ——Thanks in advance!!——Please also continue to pay attention, everyone...

Looking forward...
Floor 30 Posted 2008-02-01 03:24 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Originally planned to sleep, but still finished writing it (there is Example.vbs, modify it and then delete it, otherwise the desktop is messy), basically the structure is set according to the previous script.

Example2.vbs:

Const ForReading = 1 'Set the text opening method to reading
Const ForWriting = 2 'Set the text opening method to writing
Const ForAppending = 8 'Set the text opening method to appending

Const InFile = "a.txt" 'Set the text to open

Dim i
Dim StrLine,OutStr
i = 1

'On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject") 'Reference the FSO object, which is used for reading and writing files
Set objFile = objFSO.OpenTextFile(InFile, ForReading) 'Open InFile in reading mode

Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine 'Read a line
If Len(StrLine) Then 'If it is not an empty line
StrLine = FixStr(StrLine)
NeedData = Split(StrLine," ")
If Right(NeedData(1),1) = "*" Then NeedData(1) = Left(NeedData(1),Len(NeedData(1)) - 1)
OutLine = "2140800050202" & NeedData(1) & "3" & AddZero(i,6) & "00" & NeedData(2)
OutLine = OutLine & "000000000000000011 " & AddZero(i - 1,9) & NeedData(4)
OutStr = OutStr & OutLine & vbCrLf
i = i + 1
End If
Loop
OutStr = OutStr & "14080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00000000001775000000000000000000072 " 'Did you miss writing 2 above? The meaning of 2 is unclear.


objFile.Close 'Close the file object


OutFile = "140820" & FormatDate(Date) & "001.txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting,True) 'Open OutFile in writing mode
objFile.Write OutStr
objFile.Close 'Close the file object

Set objFile = Nothing
Set
objFSO = Nothing

Function
FixStr(StrExp)
Do While InStr(StrExp," ")
StrExp = Replace(StrExp," "," ")
Loop
FixStr = StrExp
End Function

Function
FormatDate(tDate)
FormatDate = Right(Year(tDate),2) & AddZero(Month(tDate),2) & AddZero(Day(tDate),2)
End Function

Function
AddZero(sNum,iLen)
Addzero = Right("000000000" & sNum,iLen)
End Function






Wrote quote as code... -.-
Forum Jump: