Board logo

标题: [文本处理] 批处理怎样获取/提取多个txt文件的最后一行并输出到同一个txt文本里? [打印本页]

作者: 冷水茶    时间: 2013-9-10 07:25     标题: 批处理怎样获取/提取多个txt文件的最后一行并输出到同一个txt文本里?

本帖最后由 pcl_test 于 2017-4-10 13:59 编辑

本人新手,想要把多个txt文件的最后一行提取出来并输出到一个txt文件里面
跪求高手解答
作者: batman    时间: 2013-9-10 08:12

  1. @echo off&setlocal enabledelayedexpansion
  2. (for %%a in (*.txt) do (
  3.   for /f "usebackq delims=" %%b in ("%%a") do set "str=%%b"
  4.   echo,!str!
  5. ))>$
  6. move $ new.txt
  7. start new.txt
复制代码

作者: ivor    时间: 2013-9-10 09:24

move $ new.txt  

这一条不属于多余吗?
作者: batman    时间: 2013-9-10 09:48

回复 3# ivor


    如果是用dir遍历就是多余的,但是如果是用for /r或for来遍历就是很有必要的。。。
作者: PowerShell    时间: 2013-9-10 09:51

for %%a in (*.txt) ---这句是只支持ansi编码文件么?
试试这句powershell代码
  1. Get-Content *.txt -tail 1  > d:\aaa.txt
复制代码
我记得貌似 powershell 帮助上有类似的案例。
作者: Batcher    时间: 2013-9-10 10:21

回复 5# PowerShell


    遇到其它编码的文件时第一个for循环没有问题,可能出问题的是第二个for循环。
作者: c26318892    时间: 2013-9-13 11:21

如果是要抽出最後一行文件內部不要留著呢?




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2