Hello
Below is a script which Gertone kindly sorted for me - however, I've noticed that if I use file extension.csv then I get many commas after column 1 - for example .
More Than Availability Over Time,,,,,, 08/08/2008 00:00,5,143,GB04QAP050TOP2
7,100,6
If I use file extension .txt then I get one comma after column1 then none thereafter - for example ..
More Than Availability Over Time, 08/08/2008 00:00 5 143 GB04QAP050TOP27 100 6
This causes me a problem when uploading into msaccess - any help much appreciated and source file attached - if required.
my_path = "U:\\Phil_Sivyer\\4_Availa
bility\\me
rcury_file
s_received
_daily\\"
# put the local filenames of theinput files here
file_lst = ["08082008.txt", "09082008.txt"]
sink = File.open(my_path + "joined.txt", "w")
# loop over the array with all the filenames listed
file_lst.each do |fl|
# open the file and access each single line
waiting_for_header = 1
first_header_line = "first line"
File.open(my_path + fl, "r").each do |line|
if line =~ /^$/ then
elsif line =~ /^\d+\/\d+\/\d+/ then
waiting_for_header = 1
sink.write(first_header_li
ne + ", " + line)
elsif waiting_for_header == 1 then
waiting_for_header = 0
first_header_line = line.rstrip!
end
end
end
sink.close()
Start Free Trial