中国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-08-06 02:14
48,039 topics / 350,124 posts / today 2 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » [Solved] Add line numbers to a txt document
Printable Version  948 / 14
Floor1 userwww Posted 2007-10-10 16:00
初级用户 Posts 57 Credits 136
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 ]
Floor2 huzixuan Posted 2007-10-10 16:20
高级用户 Posts 219 Credits 537 From 芜湖
Floor3 userwww Posted 2007-10-10 16:27
初级用户 Posts 57 Credits 136
Solved it, thanks huzixuan
Floor4 huzixuan Posted 2007-10-10 16:34
高级用户 Posts 219 Credits 537 From 芜湖
Because that %%b for loop is nested inside %%a, every line of %%a has to execute the %%b loop
Floor5 userwww Posted 2007-10-10 16:46
初级用户 Posts 57 Credits 136
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 ]
Floor6 huzixuan Posted 2007-10-10 16:52
高级用户 Posts 219 Credits 537 From 芜湖
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?
Floor7 userwww Posted 2007-10-10 16:57
初级用户 Posts 57 Credits 136
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
Floor8 huzixuan Posted 2007-10-10 17:01
高级用户 Posts 219 Credits 537 From 芜湖
"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?
Floor9 userwww Posted 2007-10-10 17:05
初级用户 Posts 57 Credits 136
Floor10 userwww Posted 2007-10-10 17:07
初级用户 Posts 57 Credits 136
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
Floor11 huzixuan Posted 2007-10-10 17:20
高级用户 Posts 219 Credits 537 From 芜湖

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
Floor12 userwww Posted 2007-10-10 18:04
初级用户 Posts 57 Credits 136
Floor13 bbq5201 Posted 2007-10-11 00:51
初级用户 Posts 51 Credits 136
For the OP's first question... can FOR /L be used to mark line numbers?
Floor14 userwww Posted 2007-10-11 13:42
初级用户 Posts 57 Credits 136
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
Floor15 kangdf Posted 2007-10-11 21:11
新手上路 Posts 2 Credits 4
Learning
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023