...I used some of Unix but sometimes I have to work with something else which in this case there is a macro VB script that I need to add more to exist Unix scripts and I'm not VB person.
Nor is English your first language, but that's okay; I think I got the idea.
I generally avoid using Excel if I'm parsing text in scripts; it's powerful, but not universal.
Even if you are dead-set on using Excel as an (overpowered) text parser, I also have misgivings about doing this from a VBA macro in Excel. You'd have to open whatever workbook holds the macro, then run the script. I'd rather have a VBScript that invokes Excel as needed. As such, the following script should be saved as <whatever>.vbs.
But first, questions!
1: Depends on your definition of 'Macro,' but probably. I'd probably break it up into at least two pieces for readability, though.
2: You'd have to handle the possibility, or risk the script bombing out.
Dim files, e, errLvl
'Modify this list as needed
files = Array (_
"1.txt", _
"2.txt", _
"3.txt")
Set e = CreateObject("Excel.Application")
e.DisplayAlerts = False
'Feel free to delete this line
e.Visible = True
For Each s In files
errLvl = errLvl * 2 + ParseFile(e, s)
Next
'Cleanup
e.Quit
WScript.Quit errLvl
Function ParseFile(oExcel, sFile)
On Error Resume Next
Dim r, i
With oExcel
'Try 1 or 3 (instead of 2) if data isn't parsing right
.Workbooks.OpenText sFile, 2, _
4, 1, -4142, True, True
'^---- Step #1 (No Headers)
'File opened okay?
If Err Then
Err.Clear
ParseFile = 1
Exit Function
End If
With .Workbooks(1).Worksheets(1)
'File empty?
Set r = .Cells.SpecialCells(11).EntireRow.Cells(1)
If r.Address = "$A$1" And Trim(r.Formula) = "" Then
ParseFile = 1
oExcel.Workbooks(1).Close False
Exit Function
End If
'Step #3 (Add Date)
Set r = .Cells.SpecialCells(11).Offset(0,1)
For Each r In .Range(r, r.EntireColumn.Cells(1))
r.Formula = Date
Next
'Step #4 (Delete Footer)
Set r = .Cells.Find("Total Records:",_
.Cells(1), -4163, 2)
Do Until r Is Nothing
r.Offset(-1, 0).EntireRow.Delete
r.EntireRow.Delete
Set r = .Cells.FindNext()
Loop
'Step #2 (Remove columns 6 - 8)
For i = 8 To 6 Step -1
.Columns(i).Delete
Next
End With
'Step #5 (Save)
.Workbooks(1).Save
'Final check for problems
If Err Then _
ParseFile = 1
.Workbooks(1).Close False
End With
End Function