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-08-06 01:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] Add line numbers to a txt document View 946 Replies 14
Original Poster Posted 2007-10-10 16:00 ·  中国 广东 东莞 电信
初级用户
★★
Credits 136
Posts 57
Joined 2007-09-08 11:11
18-year member
UID 96854
Gender Male
Status Offline
For the existing text a.txt, the line numbers should not start from 1, but should start flowing from a specified value (for example 20), and a "+" symbol should be added at the end of each line number. The link below doesn't meet this requirement,
http://www.cn-dos.net/forum/viewthread.php?tid=30749&fpage=1&highlight=txt

I referred to and modified some expert's P below, but found that every line in A.txt gets numbered 20~100. Please advise.

for /f %%a in (a.txt) do (
for /L %%b in (20,1,100) do (
echo %%b +%%a >> b.txt
)
)

Solved, many thanks to the friend in reply #2

[ Last edited by userwww on 2007-10-10 at 10:36 PM ]
Floor 2 Posted 2007-10-10 16:20 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
userwww +2 2007-10-10 16:26
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 3 Posted 2007-10-10 16:27 ·  中国 广东 东莞 电信
初级用户
★★
Credits 136
Posts 57
Joined 2007-09-08 11:11
18-year member
UID 96854
Gender Male
Status Offline
Solved it, thanks huzixuan
Floor 4 Posted 2007-10-10 16:34 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Because that %%b for loop is nested inside %%a, every line of %%a has to execute the %%b loop
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 5 Posted 2007-10-10 16:46 ·  中国 广东 东莞 电信
初级用户
★★
Credits 136
Posts 57
Joined 2007-09-08 11:11
18-year member
UID 96854
Gender Male
Status Offline
Nowadays many MP3 players can display lyrics. For them to display properly, the lyric file (*.lrc) must have the same name as the song file (*.mp3)

Directory A contains *.Lrc lyric files (with multiple subdirectories), and directory B contains *.MP3 files (also with multiple subdirectories). Since I want to later download some songs and lyrics into my portable player, the lyric filenames and MP3 filenames must correspond. I want to 1. find the Lrc files under directory A that do not correspond to anything in directory B and delete them, 2. find the MP3 files under directory B that have no lyrics

This batch file only handles the current directory. How can it also handle subdirectories?

@echo off
del G:\list.txt>nul 2>nul
echo ---G:Music\01 >G:\list.txt
cd /d G:\music\01
for %%i in (*.mp3 *.wma) do (if not exist %%~ni.lrc echo %%~ni>>G:\list.txt)
echo ---G:Music\02 >>G:\list.txt
cd /d G:\Music\02
for %%i in (*.mp3 *.wma) do (if not exist %%~ni.lrc echo %%~ni>>G:\list.txt)
notepad G:\list.txt
exit

Original linkhttp://www.cn-dos.net/forum/viewthread.php?tid=23518&fpage=1&highlight=%E6%AD%8C%E8%AF%8D

[ Last edited by userwww on 2007-10-10 at 06:18 PM ]
Floor 6 Posted 2007-10-10 16:52 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Do the lyric files in directory A and the MPE files in directory B match up one by one?
For example, would A\1\歌曲.lrc correspond to B\2\歌曲.mp3?
How should "not corresponding" be understood?
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 7 Posted 2007-10-10 16:57 ·  中国 广东 东莞 电信
初级用户
★★
Credits 136
Posts 57
Joined 2007-09-08 11:11
18-year member
UID 96854
Gender Male
Status Offline
The file locations do not necessarily correspond.
For example A\1\Chinese Man.Lrc B\2\Chinese Man.Mp3

But the lyric name "Chinese Man" and the song name "Chinese Man" must correspond. If the song name has spaces, then the lyric name must also have matching spaces
Floor 8 Posted 2007-10-10 17:01 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
"1. find the Lrc files in directory A that do not correspond to anything in directory B and delete them"
What does that mean? How do you determine that they do not correspond?
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 9 Posted 2007-10-10 17:05 ·  中国 广东 东莞 电信
初级用户
★★
Credits 136
Posts 57
Joined 2007-09-08 11:11
18-year member
UID 96854
Gender Male
Status Offline
Floor 10 Posted 2007-10-10 17:07 ·  中国 广东 东莞 电信
初级用户
★★
Credits 136
Posts 57
Joined 2007-09-08 11:11
18-year member
UID 96854
Gender Male
Status Offline
Same discussion as this thread, but that thread is about matching in a directory without subdirectories, http://www.cn-dos.net/forum/viewthread.php?tid=23518&fpage=1&highlight=%E6%AD%8C%E8%AF%8D
Floor 11 Posted 2007-10-10 17:20 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline

@echo off
for /f "delims=" %%i in ('dir /b /s b\*.mp3') do (
dir /b /s "a\%%~ni".lrc >nul 2>nul||>>没有歌词的mp3文件.txt echo %%i
)

2. find the MP3 files in directory B that have no lyrics in A
I don't know how to define "do not correspond" for the first one
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 12 Posted 2007-10-10 18:04 ·  中国 广东 东莞 电信
初级用户
★★
Credits 136
Posts 57
Joined 2007-09-08 11:11
18-year member
UID 96854
Gender Male
Status Offline
Floor 13 Posted 2007-10-11 00:51 ·  中国 广东 广州 荔湾区 电信
初级用户
★★
Credits 136
Posts 51
Joined 2007-08-04 21:31
19-year member
UID 94657
Gender Male
Status Offline
For the OP's first question... can FOR /L be used to mark line numbers?
Floor 14 Posted 2007-10-11 13:42 ·  中国 广东 东莞 电信
初级用户
★★
Credits 136
Posts 57
Joined 2007-09-08 11:11
18-year member
UID 96854
Gender Male
Status Offline
Originally posted by bbq5201 at 2007-10-11 12:51 AM:
For the OP's first question... can FOR /L be used to mark line numbers?


With For /L, the line numbers start from 1; it seems they can't start from a specified value
Floor 15 Posted 2007-10-11 21:11 ·  中国 广东 深圳 宝安区 电信
新手上路
Credits 4
Posts 2
Joined 2007-10-11 20:50
18-year member
UID 99479
Gender Male
Status Offline
Learning
Forum Jump: