batch-file - 寻找可以处理超过 65534 行文件的 MORE/MOVE 解决方案
问题描述
我有许多唯一命名的 .CSV 文件,我需要从中删除前 17 行。其中一些文件超过 65534 行,因此我的 MORE/MOVE Batch 脚本无法正常工作。寻找替代解决方案。
@echo off
for %%a in (*.csv) do (
more +17 "%%a" >"%%a.new"
move /y "%%a.new" "%%a" >nul
)
无论输入的行数如何,我都希望删除 17 个标题行并构建所有剩余行的新文件。
解决方案
制定自己的cut
命令。这是移植到 VB.NET 的 VBScript。
切
cut {t|b} {i|x} NumOfLines
从文件的顶部或底部剪切行数。
t - top of the file
b - bottom of the file
i - include n lines
x - exclude n lines
例子
cut t i 5 < "%systemroot%\win.ini"
剪切.bat
REM Cut.bat
REM This file compiles Cut.vb to Cut.exe
REM Cut.exe Removes specified from top or bottom of lines from StdIn and writes to StdOut
REM To use
REM cut {t|b} {i|x} NumOfLines
Rem Cuts the number of lines from the top or bottom of file.
Rem t - top of the file
Rem b - bottom of the file
Rem i - include n lines
Rem x - exclude n lines
Rem
Rem Example - Includes first 5 lines Win.ini
Rem
Rem cut t i 5 < "%systemroot%\win.ini"
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\Cut.exe" "%~dp0\Cut.vb" /verbose
pause
剪切.vb
'DeDup.vb
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Module DeDup
Sub Main
Dim Arg() As Object
Dim RS as Object
Dim LineCount as Object
Dim Line as Object
Arg = Split(Command(), " ")
rs = CreateObject("ADODB.Recordset")
With rs
.Fields.Append("LineNumber", 4)
.Fields.Append("Txt", 201, 5000)
.Open
LineCount = 0
Line=Console.readline
Do Until Line = Nothing
LineCount = LineCount + 1
.AddNew
.Fields("LineNumber").value = LineCount
.Fields("Txt").value = Console.readline
.UpDate
Line = Console.ReadLine
Loop
.Sort = "LineNumber ASC"
If LCase(Arg(0)) = "t" then
If LCase(Arg(1)) = "i" then
.filter = "LineNumber < " & LCase(Arg(2)) + 1
ElseIf LCase(Arg(1)) = "x" then
.filter = "LineNumber > " & LCase(Arg(2))
End If
ElseIf LCase(Arg(0)) = "b" then
If LCase(Arg(1)) = "i" then
.filter = "LineNumber > " & LineCount - LCase(Arg(2))
ElseIf LCase(Arg(1)) = "x" then
.filter = "LineNumber < " & LineCount - LCase(Arg(2)) + 1
End If
End If
Do While not .EOF
Console.writeline(.Fields("Txt").Value)
.MoveNext
Loop
End With
End Sub
End Module
推荐阅读
- flutter - 如何在颤动中使用自定义部分标题实现水平列表视图?
- jquery - 如果用户选择了一次,则将来禁用单选按钮选择
- python - 为什么 datetime.today.minute 没有给出实际分钟数?
- amazon-web-services - 有没有办法在多次请求后删除或隐藏对对象的公共访问?
- corda - 如何将 Corda 服务公开给 RPC,尤其是在使用 JPA 的情况下
- css - 使用 mixins 返回媒体查询
- javascript - 如何将浮点数增加最低零
- sql - 左连接,多列联合选择
- java - JavaFX:如何创建带有通知徽章的应用程序图标?
- node.js - 如何将多个 url 组合成一个 websocket?