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-27 14:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Batch statistics of valid phone numbers in text and paste them into an Excel sheet? View 1,819 Replies 10
Original Poster Posted 2009-09-17 06:58 ·  中国 四川 广安 电信
新手上路
Credits 6
Posts 6
Joined 2009-09-16 03:11
16-year member
UID 152093
Gender Male
Status Offline
Now I have many files like those in the attachments. The purpose is to extract the valid numbers that this person often contacts. Exclude things like 1008611, 10661700, etc. And paste the extracted 10 valid numbers into a certain column of the row corresponding to this file name in an Excel spreadsheet, because there are really too much data. Before, I always used Excel sorting and did it manually. The efficiency is too low. And it's really torturing. I've tried many methods and don't know what to do. Helpless! Hope a master can give a clue. Just a train of thought is okay. What is specifically better to solve it. Before, I found a software called replace pioneer. There is a tool called pattern counter in it that can import text files and count and sort. Just set parameters, such as \d{7,} is to count data with 7 or more digits, but this software can't let me batch process so many files. Troubled oh.
Floor 2 Posted 2009-09-17 07:02 ·  中国 四川 广安 电信
新手上路
Credits 6
Posts 6
Joined 2009-09-16 03:11
16-year member
UID 152093
Gender Male
Status Offline
Can you find the file I uploaded? It's called 1693.txt, uploaded for the first time. In which upload system is it?
Floor 3 Posted 2009-09-17 07:03 ·  中国 广东 电信
新手上路
Credits 14
Posts 14
Joined 2009-09-08 06:17
16-year member
UID 151679
Gender Male
Status Offline
Didn't see it...
Floor 4 Posted 2009-09-17 08:14 ·  中国 四川 广安 电信
新手上路
Credits 6
Posts 6
Joined 2009-09-16 03:11
16-year member
UID 152093
Gender Male
Status Offline
http://upload.cn-dos.net/img/1693.txt
I really don't know how to upload files. I'm illiterate. Is this okay?
Floor 5 Posted 2009-09-17 08:35 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Notes:
1. This batch processing requires a third-party command-line tool sed.exe, which can be downloaded from the URL http://ishare.iask.sina.com.cn/f/5621524.html, then saved in the same directory as the batch processing, or placed in the system32 directory.
2. 1693.txt is the original source file, and I.txt is the output file.
3. >I.txt echo 序号 次数 电话号码, there are tabs in the middle, not a string of spaces.
4. if !C! lss 11 >>I.txt echo !C! !E! %%j), there are tabs in the middle, not a string of spaces.

@echo off&setlocal enabledelayedexpansion&>I.txt echo 序号	次数	电话号码
for /f "delims=" %%i in ('sed "s//\n/g" 1693.txt ^| findstr ^*$') do (set A=%%i
if "!A:~0,3!" neq "000" if "!A:~0,2!" neq "10" if "!A:~0,4!" neq "2009" (if "!A:~0,5!" == "17951" set A=!A:~5!)&set /a A_!A!+=1)
for /f "tokens=2,3 delims==_" %%i in ('set ^| findstr "^A_"') do set B=00000000%%j&set C_!B:~-9!:%%i==
for /f "tokens=2,3 delims==_:" %%i in ('set ^| findstr "^C_" ^| sort /r') do (set /a C+=1
call :D %%i
if !C! lss 11 >>I.txt echo !C! !E! %%j)
start notepad I.txt&exit
:D
set E=%1
:F
if "!E:~0,1!" == "0" set E=!E:~1!&goto F


Example of output result:
Serial number Times Telephone number
1 1280 134****0555
2 1163 135****8816
3 154 137****5982
4 76 081****2445
5 48 800****54107
6 44 132****5767
7 43 153****1636
8 43 132****3700
9 35 138****4200
10 26 159****6315
......


You can directly paste this text into Excel.

[ Last edited by Hanyeguxing on 2009-9-18 at 07:53 ]
Floor 6 Posted 2009-09-17 09:04 ·  中国 四川 广安 电信
新手上路
Credits 6
Posts 6
Joined 2009-09-16 03:11
16-year member
UID 152093
Gender Male
Status Offline
No, no. The number I extracted is the number he often contacts others with, just to find the person himself. Don't filter out numbers with less than 10 digits. I mean, find the numbers of the 10 people he often contacts, such as 13688888888, 15988888888, 8234888, 0107654321, etc. Don't worry about arranging them. Just paste the top 10 numbers that appear more frequently.
Floor 7 Posted 2009-09-17 11:10 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
@echo off
Turn off echoing and do not display this line.
setlocal enabledelayedexpansion
Enable variable delay.
>I.txt echo Serial number Number of times Phone number
Create the text I.txt and output the content "Serial number Number of times Phone number".
sed "s//\n/g" T.txt
Extract all numbers in the text, each group of numbers is on an independent line, and ignore all sensitive characters.
findstr ^*$
Search for numbers that meet the conditions from the result set of the sed operation, that is, numbers with 7 or more digits.
for /f "delims=" %%i in (
Parse the result set of sed and findstr.
set A=%%i
Assign the value obtained from the parsing to variable A.
if "!A:~0,3!" neq "000"
Intercept the first 3 characters of variable A, judge whether it is 000, otherwise...
if "!A:~0,2!" neq "10"
Intercept the first 2 characters of variable A, judge whether it is 10, otherwise...
if "!A:~0,4!" neq "2009"
Intercept the first 4 characters of variable A, judge whether it is 2009, otherwise... (The above 3 if statements are in logical AND.)
if "!A:~0,5!" == "17951" set A=!A:~5!
Intercept the first 5 characters of variable A, judge whether it is 17951, if yes, intercept its 6th character and all characters behind it, and assign it to variable A.
set /a A_!A!+=1
Set the variable set and count. Among them, the variable name is: A_!A! : A_ is the prefix,!A! is the latter part, obtained by the above 4 if statements.
set
Output all environment variables.
findstr "^A_"
Filter out all variables whose variable names start with A_ from the environment variables.
for /f "tokens=1,2 delims==_" %%i in (
Parse the filtered environment variables, with = and _ as the section delimiters. The variable name is assigned to %%i, and the value of the variable is assigned to %%j.
set B=00000000%%j
Add 8 zeros in front of variable %%j and assign it to variable B.
set C_!B:~-9!:%%i==
Set the variable set. The value of each variable is =. The variable name is C_!B:~-9!:%%i, where C_ is the prefix, B:~-9! is the front part, obtained by intercepting the last 9 characters of variable B, : is the middle part, used for the next statement separation, %%i is the latter part.
findstr "^C_"
Filter out all variables whose variable names start with C_ from the environment variables.
sort /r
Sort the result set of findstr, /r specifies reverse sorting.
for /f "tokens=1,2 delims==_:" %%i in (
Parse the filtered environment variables, with =, _ and : as the section delimiters. The first half of the variable name is assigned to %%i, and the second half of the variable name is assigned to %%j.
set /a C+=1
Add to the count and assign the cumulative value to variable C.
call :D %%i
Call the label :D and pass variable %%i as the first parameter %1.
>>I.txt echo !C! !E! %%j
Output variables!C!,!E! and %%j.
if!C! lss 11 (
Judge whether variable C is less than 11, if yes...
start notepad I.txt
Open the text I.txt with the notepad program and do not wait for the program to close and exit.
exit
Exit this batch processing.
set E=%1
Set the passed parameter %1 as variable E.
if "!E:~0,1!" == "0" set E=!E:~1!&goto F
Intercept the first character of variable E and judge whether it is 0. If not, exit the label :D; if it is 0, intercept the 2nd character and all characters behind it, that is, remove this 0, and assign it to variable E. Then return to label :F and repeat this operation until there are no 0s at the beginning of variable E.

[ Last edited by Hanyeguxing on 2009-9-18 at 08:02 ]
Floor 8 Posted 2009-09-18 03:33 ·  中国 四川 广安 电信
新手上路
Credits 6
Posts 6
Joined 2009-09-16 03:11
16-year member
UID 152093
Gender Male
Status Offline
Hehe, really easy to use. I just tried it. The remaining part is that I should好好 digest and study these codes well to modify them into something really suitable for myself. Also, can these 10 numbers be automatically imported into a specified position of an Excel sheet? And then, all the txt original data in a folder can be automatically imported into Excel one by one like this one.
Floor 9 Posted 2009-09-18 06:56 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
You can combine multiple such processed texts into one text, separated by tabs, and finally paste it into Excel at one time
Floor 10 Posted 2009-09-18 08:56 ·  中国 四川 广安 电信
新手上路
Credits 6
Posts 6
Joined 2009-09-16 03:11
16-year member
UID 152093
Gender Male
Status Offline
Well, there are still many issues that need to be addressed. I just started getting into this, and the code looks really archaic. I'll digest it slowly and then ask questions. In the end, I still have to rely on my own efforts. I can't just ask every time I don't understand something. Thanks everyone for leading me into this door. The warm socialist big family
Floor 11 Posted 2009-10-02 10:12 ·  中国 辽宁 沈阳 联通
新手上路
Credits 1
Posts 1
Joined 2009-10-01 14:51
16-year member
UID 152502
Gender Male
Status Offline
Take your time and study~~
Forum Jump: