Zack
asked on
Split a CSV file into 2 files based on date.
Hi EE,
Can you split a CSV file using PowerShell by specific date range, e.g split csv file into two everything before may 30 2018 on the first file and everything after on the second file?
2019-04-30 08:15:34.607 - This is date time format of the file I have and it's the first column of the CSV file.
Any assistance is welcome.
Thank you.
Can you split a CSV file using PowerShell by specific date range, e.g split csv file into two everything before may 30 2018 on the first file and everything after on the second file?
2019-04-30 08:15:34.607 - This is date time format of the file I have and it's the first column of the CSV file.
Any assistance is welcome.
Thank you.
ASKER
Hi HuaMin,
What do you mean?
Thank you.
What do you mean?
Thank you.
Hi,
You can write to different text file like
per different date you can see from original csv file.
You can write to different text file like
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("C:\your_path\vba.txt", True, True)
Fileout.Write "your string goes here"
Fileout.Close
per different date you can see from original csv file.
ASKER
HI Huamin,
But's not a txt file it's CSV, as per my request how do I split a CSV into two files based on specific date value.
Thank you.
But's not a txt file it's CSV, as per my request how do I split a CSV into two files based on specific date value.
Thank you.
CSV file is definitely Text file and you could use VBA code to tackle with it.
4. Add the following code line:
Open myFile For Input As #1
Note: this statement allows the file to be read. We can refer to the file as #1 during the rest of our code.
5. Add the following code lines:
Do Until EOF(1)
Line Input #1, textline
text = text & textline
Loop
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Guys ,
Cheers, this has given something for me to play around with many thanks.
Cheers, this has given something for me to play around with many thanks.
Use Loop to copy specific line into different Text file, per the date captured, inside the file.