您可以在 Excel 中打开列表,以便所有要操作的数据进入 A 列,然后使用如下公式在 B、C、D 列中创建 UNIX 命令:
第一个命令:
="grep -i " &LOWER(LEFT(A:A,FIND(" ",A:A))) & " */*.cfg"
第二条命令:
="grep -i "&LOWER(LEFT(TRIM(MID(A:A,FIND(" ",A:A),LEN(A:A))),FIND(" ",TRIM(MID(A:A,FIND(" ",A:A),LEN(A:A))))))&" */*.cfg"
第三条命令:
="grep -i "&LOWER(MID(RIGHT(A:A,LEN(A:A)-FIND(" ",A:A)),FIND(" ",RIGHT(A:A,LEN(A:A)-FIND(" ",A:A))),LEN(RIGHT(A:A,LEN(A:A)-FIND(" ",A:A)))))&" */*.cfg"
在 A 列中处理完所有 texdt 后,将 B、C、D 列中的公式复制下来
然后你可以运行下面的代码(可能需要调整)来创建你的输出:
Sub getCommands()
Dim oFso As New Scripting.FileSystemObject
Dim oWriteFile As TextStream
Dim oRange As Range
Set oWriteFile = oFso.CreateTextFile("C:\Commands.txt", True)
Set oRange = Range("B2")
Do Until oRange.Text = ""
With oWriteFile
.WriteLine oRange.Text
.WriteLine oRange.Offset(0, 1).Text ' second command
.WriteLine oRange.Offset(0, 2).Text ' third command
End With
Set oRange = oRange.Offset(1, 0)
Loop
oWriteFile.Close
End Sub