Skip to content

通过 python 脚本为 txt 文档的每一行添加索引号 / add line numbers to txt file via python script

License

Notifications You must be signed in to change notification settings

x1ao4/line-indexer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

line-indexer

使用 line-indexer 可以为你的文本自动逐行添加索引号。

功能演示

假设input.txt文件中的内容如下:

apple
banana
cherry

运行脚本后,output.txt文件中的内容将变为:

1;apple
2;banana
3;cherry

每一行前面都添加了一个索引号,用;与原来的内容分隔。

必备条件

请确保您的系统上安装了 Python 3.6 或更高版本。

使用方法

  1. 将仓库克隆或下载到计算机上的一个目录中。
  2. 修改start.command (Mac)start.bat (Win)中的路径,以指向您存放line-indexer.py脚本的目录。
  3. 将要处理的文本保存为input.txt文件,并放在与脚本相同的目录中。
  4. 双击运行start.commandstart.bat脚本以执行line-indexer.py脚本。
  5. 结果将写入到同一目录下名为output.txt的文件中。

您也可以通过编辑line-indexer.py脚本中{i};{line}的部分来自定义分隔符,将;替换为您想要的分隔符即可。


line-indexer

With line-indexer, you can automatically add line numbers to your text file.

Example

Assuming the contents of theinput.txtfile are as follows:

apple
banana
cherry

After running the script, the content of theoutput.txtfile will be:

1;apple
2;banana
3;cherry

A line index number is added before each line, separated by a;from the original content.

Requirements

Make sure you have Python 3.6 or higher installed on your system.

Usage

  1. Clone or download the repository to a directory on your computer.
  2. Modify the path instart.command (Mac)orstart.bat (Win)to point to the directory where you store theline-indexer.pyscript.
  3. Save the text to be processed as aninput.txtfile and place it in the same directory as the script.
  4. Double-clickstart.commandorstart.batto execute theline-indexer.pyscript.
  5. The result will be written to a file namedoutput.txtin the same directory.

You can also customize the separator by editing the{i};{line}part in theline-indexer.pyscript. Simply replace;with your desired separator.

About

通过 python 脚本为 txt 文档的每一行添加索引号 / add line numbers to txt file via python script

Topics

Resources

License

Stars

Watchers

Forks