[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理如何提取多个文本的指定行并输出到同一文本里

本帖最后由 pcl_test 于 2016-10-10 02:53 编辑

bat批处理提取多个文本文件的第三行并输出保存到ok.txt

什么写
1

评分人数

    • pcl_test: 发帖前先使用论坛搜索PB -2

脑子想动手写。
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

本帖最后由 happy886rr 于 2016-10-10 15:58 编辑

tl的用法,
提取文本文件filename的第n行到第m行
  1. tl [filename] [n] [m]
复制代码
只提取第n行
  1. tl [filename] [n]
复制代码
提取倒数第3行
  1. tl [filename] -3
复制代码
提取第5行到文件结束
  1. tl [filename] 5 -1
复制代码
基础版tl只支持utf8和ansi编码,我还是不会判断无bom的utf8,显示utf8不会乱码,且几十兆上百兆的txt也轻松在一两秒内解决掉。是more和type的替代品。速度快,体积只有3K。用base64加权压缩了。
  1. @echo off
  2. ::******Happy's 文本工具 tl.exe******
  3. set "LINE=TVqQ[M]E]//8[Lg{AQ_{][Ag]A4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJ{ABQRQ[TAEC}AO[DwMLAQY}AYBU]Q]I]AB]Q]Ag[B{[E{[Aw]Ag[NQwB[M][B[AB][E[AE{B{][ACAg[A8$_{][BcI[AX_]C50ZXh0]UAc]Q]C]AI}[C[AGAuZGF0YQ[ACAC]I]AQ]K}[B[AD${[ABVieWB7Ag[ACQu]ABQu]ABQu]ABQu]ABQuP////9Qi0UIULg]AULg]AUOhzBg[iUX4i0X4QLkB]UVDoaAY[IPECIlF/Lg]AULg]AUItF+FCLRfxQuP////9Qi0UIULg]AULg]AUOgrBg[i0X86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BwIQ[eCE[H8h[CHIQ[jiE[JYh[CeIQ[piE[K0h[C2IQ[wyE[NQh[DkIQ[6yE[Pkh[ABIg][AGtlcm5lbDMyLmRsb]FdpZGVDaGFyVG9NdWx0aUJ5dGU[ABNdWx0aUJ5dGVUb1dpZGVDaGFyAG1zdmNydC5kbGw[ABjYWxsb2M[ABmc2Vlaw[AGZlb2Y[ABmZ2V0cw[AF9pb2I[ABmcHV0cw[AGZyZWU[ABmcmVhZ]GZvcGVu]ZnRlbGw[ABhdG9p]ZmNsb3Nl]X2NvbnRyb2xmc]F9fc2V0X2FwcF90eXBl]X19nZXRtYWluYXJncw[AGV4aXQ[ABfWGNwdEZpbHRlcg[AF9leGl0]X2V4Y2VwdF9oYW5kbGVyMw@#}A="
  4. ::******Base64加权解密器*************
  5. setlocal enabledelayedexpansion
  6. set "Z=A"&(for %%Z in ([,],{,},_,$,#,-,@) do (set "Z=!Z!!Z!"&for %%S in (!Z!) do (set "LINE=!LINE:%%Z=%%S!")))&echo !LINE:.=!>base64_tl
  7. certutil -decode base64_tl tl.exe
复制代码

TOP

@echo off
setlocal enabledelayedexpansion
(for %%i in (*.txt) do (
    set "var="
    (for /l %%j in (1 1 3) do set /p var=)<"%%i"
    echo;!var!
))>ok.txt


老大说的对,多使用论坛搜索,已解决,谢谢各位

TOP

返回列表